【问题标题】:Apply a function over different dataframes在不同的数据帧上应用函数
【发布时间】:2020-03-29 06:30:26
【问题描述】:

我正在尝试在多个数据帧上同时将所有列标题转换为小写。

类似这样的东西:

  1. How to apply function to multiple pandas dataframe

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

我试过了:

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)

还有这个:

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

和:

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

在这种情况下,我不太了解多变量赋值的概念(我尝试中的 LHS 并与之相比:a, b = [True, False])

那么,如何在多个数据帧上运行一个函数?

【问题讨论】:

    标签: python pandas function dataframe


    【解决方案1】:

    试试:

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

    【讨论】:

      猜你喜欢
      • 2019-11-15
      • 2020-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-23
      • 2015-02-13
      • 2021-03-09
      • 2021-05-22
      相关资源
      最近更新 更多