慕容708150
它按列名称过滤,这里仅聚合列表中的列。['DemandRate', 'DemandRateQtr', 'AcceptRate']如果还有像此列表和列表by(此处['quote_date'])这样的其他列被省略:my_dataframe = pd.DataFrame({ 'quote_date':pd.date_range('2020-02-01', periods=3).tolist() * 2, 'DemandRate':[4,5,4,5,5,4], 'DemandRateQtr':[7,8,9,4,2,3], 'AcceptRate':[1,3,5,7,1,0], 'column':[5,3,6,9,2,4]})print(my_dataframe) quote_date DemandRate DemandRateQtr AcceptRate column0 2020-02-01 4 7 1 51 2020-02-02 5 8 3 32 2020-02-03 4 9 5 63 2020-02-01 5 4 7 94 2020-02-02 5 2 1 25 2020-02-03 4 3 0 4plot_data = (my_dataframe.query("quote_date>'2020-02-01'") .groupby(['quote_date'])[['DemandRate', 'DemandRateQtr', 'AcceptRate']] .mean() .reset_index())print (plot_data) #here is not column quote_date DemandRate DemandRateQtr AcceptRate0 2020-02-02 5.0 5.0 2.01 2020-02-03 4.0 6.0 2.5