合并两个数据框并返回整数值(如年份)的函数

时间:2018-12-24 09:00:38

标签: python-3.x

返回一个合并的DataFrame,其中包含国家/地区名称,区域和CO2排放量, 给定年份。

"ConversationStateTime": "XXXXXXXXX"

Parameters
----------
year : int
    The year of interest

Returns
-------
a DataFrame
   A pandas DataFrame with three columns titled 
   'Country', 'Region', and 'CO2 emissions'. 

def mergeByYear(year):
    yearString = str(year)
    result = pd.merge(country1, emission, on = 'Country Name')
    return 

1 个答案:

答案 0 :(得分:0)

假设您问题中的代码有效,则只需调整返回的内容即可:

def mergeByYear(year):
    yearString = str(year)
    result = pd.merge(country1, emission, on = 'Country Name')
    return result.loc[result['year'] == year]