赞
踩
data=pd.DataFrame({"Name":["苹果","谷歌","脸书","亚马逊","腾讯"],
"Conpany":["Apple","Google","Facebook","Amozon","Tencent"],
"Sale2013":[5000,3500,2300,2100,3100],
"Sale2014":[5050,3800,2900,2500,3300],
"Sale2015":[5050,3800,2900,2500,3300],
"Sale2016":[5050,3800,2900,2500,3300]})
data=data.melt(id_vars=["Name","Conpany"],value_name="Sale",var_name="Year")
print('pivot_table将长表转换成宽表')
data = data.pivot_table(index=['Name','Conpany'],columns='Year',values='Sale')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。