def sum(df,q_name,sum_index):
# df=pd.DataFrame
# pd_frame.sum()
# print(df.values)
# Aggregations(聚合),多索引,, '季度'
df_agg = df.groupby(['厂家', '季度'])['销量'].agg([np.sum])
print(df_agg)
# 列y中的值包含'6','8'的所有行。
# df_filter = df[df['city'].isin(['beijing'])]
# df_agg.to_excel(r'data\厂家.xlsx', sheet_name='2')
# index_list = df.index.unique().levels[0]
print(df_agg.ix['东江']['sum'].values.tolist() )
mybar = Bar("我的第一个图表", "这里是副标题")
mybar.add('东江', ["Q1", "Q2", "Q3", "Q4"], df_agg.ix['东江']['sum'].values.tolist())
mybar.add('格桑', ["Q1", "Q2", "Q3", "Q4"], df_agg.ix['格桑']['sum'].values.tolist())
mybar.add('浪浪', ["Q1", "Q2", "Q3", "Q4"], df_agg.ix['浪浪']['sum'].values.tolist())
mybar.show_config()
mybar.render(path=r'data\服装销量.html')
def plot(df):
mybar = Bar("我的第一个图表", "这里是副标题")
mybar.add(df, ["衬衫", "羊毛衫", "雪纺衫", "裤子"], df.ix['东江']['sum'].values.tolist())
mybar.show_config()
mybar.render()
pd_frame=read(r'data\服装销量.xlsx');
# q_name='季度'
# sum_index='销量'
sum(pd_frame, 'two', '')
# get_data()```
数据
季度品名销量厂家Q1衬衫5浪浪Q2 羊毛衫20浪浪Q3 雪纺衫36浪浪Q4 裤子9浪浪Q1高跟鞋60浪浪Q2袜子84浪浪Q1衬衫8东江Q2 羊毛衫9东江Q3 雪纺衫94东江Q4 裤子9东江Q1高跟鞋24东江Q2袜子67东江Q3衬衫11格桑Q4 羊毛衫78格桑Q1 雪纺衫76格桑Q2 裤子9格桑Q3高跟鞋78格桑Q4袜子50格桑
成果物
![](https://mutouzuo.oss-cn-hangzhou.aliyuncs.com/my/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2x1YW5zag==,size_16,color_FFFFFF,t_70)
标签:mybar,Q1,格桑,df,excel,sum,汇总,柱状图,浪浪
From: https://www.cnblogs.com/bigleft/p/18179441