在大熊猫中整理我的水平条形图
我一直在尝试可视化一些数据,并将它们放在彼此堆叠的水平条形图上。
这样做时,我发现很难根据我想要的大小对它们进行分类。
我已经尝试在可视化日期之前对日期进行整理,但这无济于事。
有人可以帮我对他们排序。 谢谢
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("data.csv")
plot3 = df.groupby(['Company', 'Outcome']).size()
plot3 = plot3.unstack()
plot3[:].sort_values(('Company'), axis = 0, ascending = True).plot(kind = 'barh',color = ['r', 'g'],figsize = [15, 10], stacked = True)
#df= df.sort_values('Company', axis = 0, ascending = True,inplace = True)
plt.savefig('plot3.png')'''
[![here is what i get][1]][1]
[1]: https://i.sstatic.net/WkvY9.jpg
I have been trying to visualize some data and put them on horizontal bar charts stacked over each other.
when doing so, I find it hard to sort them based on their sizes, which I wanted.
I have tried sorting the date before visualizing it but that didn't help.
could someone please help me sort them des.
thanks
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("data.csv")
plot3 = df.groupby(['Company', 'Outcome']).size()
plot3 = plot3.unstack()
plot3[:].sort_values(('Company'), axis = 0, ascending = True).plot(kind = 'barh',color = ['r', 'g'],figsize = [15, 10], stacked = True)
#df= df.sort_values('Company', axis = 0, ascending = True,inplace = True)
plt.savefig('plot3.png')'''
[![here is what i get][1]][1]
[1]: https://i.sstatic.net/WkvY9.jpg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以按
DataFrame 对汇总行进行排序.sort_index
带有key
参数和scending=False
:或者使用
DataFrame.iloc
与Series.argsort
,-
对于负值是降序排列:You can sorting summed rows by
DataFrame.sort_index
withkey
parameter andscending=False
:Or use
DataFrame.iloc
withSeries.argsort
,-
for negative values is for descending order: