首页 > 解决方案 > 在 pandas 中组合两个表格并将它们可视化为面积图

问题描述

嘿,我在 Pandas 中上传了以下数据:

    Amerika = pd.read_csv("Amerika.csv")
Population = pd.read_excel("PopulationReport.xlsx")

Amerika 由以下列组成:Index(['state_name', 'overall_outcome', 'date', 'new_results_reported', 'total_results_reported'], dtype='object')

人口由以下列组成:Index(['state_name', 'Unnamed: 1', 'Unnamed: 2', 'Unnamed: 3', 'Population_2019', 'Unnamed: 5'], dtype='object')

我的问题现在如下:

America 文件显示了我每天的所有数据。我想在这里仅用整体结果 = 'Positive' 和每个州的 new_results_reported 总数(state_name)来总结这些列。

我已经用一个透视图尝试过这个,然后它准确地显示了我想要的东西。问题是,我怎样才能将表 Population.Population_2019 中的列添加到另一个表中,以便我有一个显示在第 1 列中的表:state_name in column2: total number of new_results_reported='Positive' 和最后一列各州的人口数?

这是我的 pivot_chart 代码

pivot_df = Amerika.pivot_table(index='state_name', columns='overall_outcome', values='new_results_reported', aggfunc='sum')

打印(pivot_df)

最后,我想用数据 state_name、total_results_reported ='Positive' 直观地显示这个新表,并将其与 Population_2019 计数进行比较。

美国表预览

我希望有一个人可以帮助我

标签: pythonpandasdataframevisualization

解决方案


推荐阅读