我正在尝试迭代组(由Pandas中的group.by生成)以应用函数(在MatPlotLib中创建图表)并获取DataFrame中每个组的结果。我想做这样的事情,但我知道有更好/更实用的方式:
import pandas as pd
DF = pd.DataFrame({'COL1': ['A', 'A','B','B'],
'COL2' : [1,1,2,2],
'COL3' : [2,3,4,5]})
unique_list = set(df['COL1'])
for group in unique_list:
if group == df['COL1']:
<apply function to df['COL3']
one group at a time,
starting with df['COL1'] == 'A'>