将数据行转换列显示
# DISCLAIMER: 'df' refers to the data you passed in when calling 'dtale.show'
import pandas as pd
df = pd.pivot_table(df, index='['商品编号']', columns='['地点名称']', values=['销售金额', '销售数量'], aggfunc='sum')
df.columns = ['\n'.join([str(c) for c in col]).strip() for col in df.columns.values]
df = df.rename_axis(None, axis=1)
if isinstance(df, (pd.DatetimeIndex, pd.MultiIndex)):
df = df.to_frame(index=False)
# remove any pre-existing indices for ease of use in the D-Tale code, but this is not required
df = df.reset_index().drop('index', axis=1, errors='ignore')
df.columns = [str(c) for c in df.columns] # update columns to strings in case they are numbers
原创2022/9/14小于 1 分钟