绘图条形图带有多列图
我有一个类似的数据集:
Female Male Single Married Cohabit OthSing
1 0 1 0 0 0
0 1 0 1 0 0
0 1 0 0 0 1
1 0 0 0 1 0
0 1 1 0 0 0
1 0 0 0 1 0
基本上,如果您有1个女性,则男性为0,反之亦然。婚姻状况也是如此,如果男性/女性已婚,那么它就不可能单身或同居。我想使用包含4个酒吧(婚姻状况)的Plotly绘制条形图,我不在乎它是男性还是女性,我只想知道有多少人是单身,已婚,同居或其他类型单人。我的问题是每个栏都来自另一列,我还找不到这样做的方法。下面的输出示例:
有人可以给我一个想法吗?
I have a dataset like this:
Female Male Single Married Cohabit OthSing
1 0 1 0 0 0
0 1 0 1 0 0
0 1 0 0 0 1
1 0 0 0 1 0
0 1 1 0 0 0
1 0 0 0 1 0
Where, basically, if you have 1 for Female, it's gonna be 0 for Male and vice versa. The same happens with the marital status, if the male/female is married, then it can't be single or cohabiting. I want to plot a bar chart using plotly that contains 4 bars (the marital status), and I don't care about if it's male or female, I just want to know how many people are single, married, cohabiting, or another kind of single. My problem is that each bar comes from a different column and I couldn't find a way to do that yet. Output example below:
Could someone give me an idea if it's possible to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许对于将来需要的人来说,我设法通过创建一个我需要的列索引,另一列的索引来绘制它,每列的计数,然后绘制列表,例如:
Maybe for someone that needs that in the future, I managed to plot it by creating a list with the indexes of the columns I needed and another one with the counts for each column and then plotted the lists, like that:
尝试此尝试,使用熊猫图:
输出:
Try this, using pandas plot:
Output: