Get data from a specific column in CSV

Asked

Viewed 268 times

0

I have a question in an exercise. I have a table where I need to get results from only one column.

the data are as follows: ['2017-01-01 00:27:45', '2017-01-01 00:31:13', '208', 'Damen Ave & Chicago Ave', 'Damen Ave & Division St', 'Subscriber', 'Male', '1982.0']]

in case need to obtain gender (male and female of the first 20 samples)... The way I’m doing I can’t just get this column and end up pulling the whole 6 line....

Hold on Give me a hand???

Segue meu código]1

  • 1

    Do not put code as image, instead put as text formatting with Ctrl + k or with the button {} question editor

1 answer

0

Juliana I advise you to use the library Pandas to work with the CSV.

In this case Voce could proceed as follows:

import pandas as pd

After importing the library, Voce must load the file. In the case below as Voce did not enter the header, I left the flag HEADER as 'None'

df = pd.read_csv('CAMINHO DO SEU ARQUIVO', header= None)

After that the file has already been loaded, and you can use the command df.info() to see how it turned out.

in the example you gave to get the data from the Column representing the genre just write the command:

print(df[6])

Following image with an example base I mounted.

inserir a descrição da imagem aqui

The PANDAS library is widely used recommend this LINK, as an introductory content

  • Thank you so much Clayton!!! I’ll try later when I get home.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.