【发布时间】:2021-05-15 15:31:13
【问题描述】:
给定三个数据框,其中包含一些国家获得的金牌、银牌和铜牌数量,确定每个国家获得的奖牌总数。 注意:所有三个数据框的国家并不完全相同。另外,按照奖牌总数降序对最终数据框进行排序。
这是我下面的代码 - 但我没有得到想要的输出。有人可以提出问题吗?
import numpy as np
import pandas as pd
# Defining the three dataframes indicating the gold, silver, and bronze medal counts
# of different countries
gold = pd.DataFrame({'Country': ['USA', 'France', 'Russia'],
'Medals': [15, 13, 9]}
)
silver = pd.DataFrame({'Country': ['USA', 'Germany', 'Russia'],
'Medals': [29, 20, 16]}
)
bronze = pd.DataFrame({'Country': ['France', 'USA', 'UK'],
'Medals': [40, 28, 27]}
)
#gold.set_index('Country',inplace = True)
#silver.set_index('Country',inplace = True)
#bronze.set_index('Country',inplace = True)
Total = gold.add(silver,fill_value = 0).add(bronze,fill_value = 0)
Total.sort_values('Medals',ascending = True)
【问题讨论】:
-
您能否编辑帖子以告诉我们您得到什么输出以及您期望什么输出?