[英]How can I plot a pd.crosstab() table?
I have a dataframe just like any other, but with two categorical columns.我有一个 dataframe 就像任何其他人一样,但有两个分类列。
Just like this:像这样:
id color size
1 blue M
2 red S
3 red M
4 blue S
5 yellow L
6 red L
And I have the distribution table:我有分布表:
pd.crosstab(df['color'],df['size'], margins=None)
Is there a way of plotting this?有没有办法绘制这个? (Just like tableau or power BI would) (就像 tableau 或 power BI 一样)
Though matplotlib and seaborn doesn't allow plotting crosstabs, you can use pandas plot for the same.尽管 matplotlib 和 seaborn 不允许绘制交叉表,但您可以使用 pandas Z32FA46E1B78A9D4A2AA 相同的。 It would look something like this:它看起来像这样:
color = ['blue', 'red', 'red', 'blue', 'yellow', 'red']
size = ['M','S','M','S','L','L']
df = pd.DataFrame((color, size), index=['color','size']).T
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.