Skip to content Skip to sidebar Skip to footer

Iterate Through Csv Columns To Create Multiple Python Dataframe

I am trying to create multiple data frames using the columns of a excel csv file. This is where I have been able to get to So the end result is I want multiple dataframes. The

Solution 1:

This does what you are asking:

all_dfs = []
for col in df.columns:
    if col != 'Date':
        df_current = df[['Date', col]]
        all_dfs.append(df_current)

Or as one line:

all_dfs = [df[['Date', col]]for col in df.columns if col != 'Date']

But you probably don't want to do that. There's not much point. What are you really trying to do?

Post a Comment for "Iterate Through Csv Columns To Create Multiple Python Dataframe"