柱状迭加图
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()