【发布时间】:2021-03-12 18:33:04
【问题描述】:
我有一个 Pandas DataFrame dfs 和一个列表 headers
列表headers 在运行时被分配DataFrame dfs 的列名。
例如,让我们考虑为列表分配dfs 的列名:
["Information_type", "Interface", "Type_of_Interface", "Connection_Mechanism"]
我想对 DataFrame dfs 执行下面的 groupby 和 agg 操作
没有明确提及 groupby 操作中的列名,即"Information_type": " ".join、"Interface": " ".join、"Type_of_Interface": " ".join、"Connection_Mechanism": " ".join:
dfs[0]=dfs[0].groupby("grp").agg({"Information_type": " ".join, "Interface": " ".join, "Type_of_Interface": " ".join, "Connection_Mechanism": " ".join})
基本上在运行时将"Information_type": " ".join , "Interface": " ".join , "Type_of_Interface": " ".join , "Connection_Mechanism": " ".join写入上述行。
如果这样的事情是可能的,那就太好了,否则我将不得不手动编辑列名并为每个表执行groupby和agg操作!
感谢您的帮助。提前致谢!
【问题讨论】:
标签: python pandas dataframe dynamic-programming