0

I am trying to turn all my column headers to lower cases simultaneously over multiple dataframes.

Something close like this:

  1. How to apply function to multiple pandas dataframe

  2. Pandas: How to apply a function to different columns

I have tried:

df_list = [df1.columns, df2.columns, df3.columns] 

df1.columns, df2.columns, df3.columns = \
       (df.apply(lambda x: x.str.lower()) for df in df_list)

and this:

for df in df_list:
    df1.columns, df2.columns, df3.columns = \
        map(str.lower, df.columns)

and:

df1.columns, df2.columns, df3.columns = (df.map(str.lower, df.columns) for df in [df1, df2, df3])

I do not really understand the concept of multiple variable assignments in this context (the LHS in my tries and compared to this: a, b = [True, False])

So, how do I run a function over multiple dataframes?

Jon
  • 51
  • 6

1 Answers1

2

Try:

df_list = [df1, df2, df3]
for df in df_list:
    df.columns = df.columns.str.lower()
luigigi
  • 4,146
  • 1
  • 13
  • 30