如何通过将pandas DataFrame从数据框中的另一列创建pandas DataFrame?
我有以下来源数据框架
国家 | 国家 | 富裕? |
---|---|---|
0 | 美国 | 是 |
1 | 印度 | 否 |
2 | 印度 | 是 |
3 | 我们 | 是 |
4 | 我们 | 否 |
是5 | 印度 | US 6 |
6 | US | 7 |
印度 | 否 | 我需要将 |
其转换另一个数据框架,以绘制以下类似的条形图,以便轻松访问数据
要创建的数据框架如下。
国家 | 贫穷的 | 贫穷 |
---|---|---|
美国 | 3 | 1 |
印度 | 1 | 3 |
我是熊猫和探索性数据科学的新手。请在这里帮忙
I have the following source dataframe
Person | Country | Is Rich? |
---|---|---|
0 | US | Yes |
1 | India | No |
2 | India | Yes |
3 | US | Yes |
4 | US | Yes |
5 | India | No |
6 | US | No |
7 | India | No |
I need to convert it another dataframe for plotting a bar graph like below for easily accessing data
Bar chart of economic status per country
Data frame to be created is like below.
Country | Rich | Poor |
---|---|---|
US | 3 | 1 |
India | 1 | 3 |
I am new to Pandas and Exploratory data science. Please help here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试
pivot_table
You can try
pivot_table
您可以这样做:
但是,如果要将其绘制为barplot,则以下格式可能与绘图库(如 seaborn :
然后,使用
seaborn
:结果图:
You could do:
However, if you want to plot it as a barplot, the following format might work best with a plotting library like
seaborn
:Then, with
seaborn
:Resulting plot: