0

Basically I need to convert a column I got a from a csv using pandas and put it into a list. It's currently a pandas object and I tried doing list(pandaObject) but that doesn't work. Does anybody have any ideas?

df = pandas.read_csv(csv_file)
years=df[['1987']]  #Gets a a column

###Now I need something to convert years to a list###
0

1 Answer 1

2

years = df[['1987']] returns a dataframe with only that column. Instead, you should first get a Series out of the column and then convert to a list:

years = df['1987'] #return a Series
years_list = years.tolist() #coverts Series to list
Sign up to request clarification or add additional context in comments.

1 Comment

This can be done in one step. years_list = df['1987'].tolist()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.