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###
K A
  • 105
  • 1
  • 2
  • 10

1 Answers1

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
amanb
  • 5,276
  • 3
  • 19
  • 38