0

I am trying to create separate lists for each column in a pandas DF and this code doesn't seem to work and not sure why:

columns = df.columns
for column in columns:
    column = list(df[column])

So, if I have a column df['LAT'], I need a series name LAT with df['LAT'] as values. I am not able to find a way to loop over all the columns to do this but when I select individuals columns it works, like:

LAT = list(df['LAT'])
aRad
  • 109
  • 1
  • 1
  • 9
  • 1
    You can check this [answer](https://stackoverflow.com/a/19122532/4819376) but I think it will be better use dictionary as inthis [one](https://stackoverflow.com/a/19122387/4819376) – rpanai Jul 21 '20 at 22:39

1 Answers1

1

It's a lot easier (and probably better) to create a dictionary where each key is the name of the column and each value is a Series:

columns = df.columns
columns_dict = {} # empty dictionary

for column_name in columns:
    # assign column to dictionary key
    columns_dict[column_name] = df[column_name].tolist()

Then the list for LAT would be accessible as columns_dict["LAT"].