柱状迭加图
柱状迭加图

蝈蝈

2022/7/31 14:20:28

group_data = df.groupby(["fl","sex"]).count()
group_data.swaplevel("fl")
group_data.columns
group_data.index
group_data.T
q = group_data.T
q.columns
q.loc["sfz"]

w=[]
m=[]
j=0
for i in q.loc["sfz"].index:
    #print(q.loc["sfz"][i])
    
    if j%2 == 0:
        w.append(q.loc["sfz"][i])
        print(q.loc["sfz"][i])
    else:
        m.append(q.loc["sfz"][i]) 
    j += 1
print(m,"\n",w)

df = pd.DataFrame({"w":w,"m":m,"c":[1,2,3,4,5,6,7,8,9]})
df

df.plot.bar(y=["w","m"],color = ["r","b"],stacked=True)
plt.xticks([0,1,2,3,4,5,6,7,8],[30,29,28,27,26,25,24,23,22])




import numpy as np
pd.DataFrame(np.random.randint(1,10,(3,4)),columns=list("abcd"))
print(data.index.levels[0])
print(data.index.levels[1])
data.loc[:,2]

df = pd.DataFrame(abs(np.random.randn(10,5)),columns=['A','B','C','D','E'],index = np.arange(0,100,10))
df.plot(kind='bar')
plt.show()




还可以输入200个字

蝈蝈派【海南省教改项目(Hnjg2022-80)支持】 网站版权所有

Python remained the copyright of our website

吉公网安备 22020402000437号

备案号:吉ICP备2020005062号-2

关注QQ群

了解Python

实时动态