如何从 Pandas 中的 Date-wise CSV 数据中查找 Year-wise 平均值用于绘制条形图

How to Find Year-wise Mean from Date-wise CSV Data In Pandas For Plotting bar chart

我有样本数据

Company,Date,Open,High,Low,Close,Adj Close,Volume
ADANIPORTS,5/6/2008,150,153.570007,147.820007,151.149994,134.313477,1782030
ADANIPORTS,5/7/2008,152,154.460007,150.240005,153.309998,136.232864,1180015
ADANIPORTS,5/8/2008,152.19996.759995,150.199997,155.889999,138.525497,1856245
ADANIPORTS,5/9/2008,155,160.600006,154.210007,156.520004,139.085312,3251375

对于不同的公司,直到 2018 年。 现在,我想找出年度开盘价和收盘价的均值来绘制条形图

这将帮助您按年分组并采取以下方式:

df.groupby(pd.Grouper(key='date', freq='Y'))['Open','Close'].mean()

否则你可以重采样方法:

df.set_index('date').resample('Y')['Open','Close'].mean()