关于熊猫的DataFrame问题

时间:2015-03-11 04:15:03

标签: python pandas dataframe series

我正在解决关于pandas中数据帧的测验问题。但是我被困住了。我编写代码但它没有给出结果。有人可以提一些建议吗?我的代码位于“#you code here”下面。

from pandas import DataFrame, Series

#################


def create_dataframe():
    #'''
    #Create a pandas dataframe called 'olympic_medal_counts_df' containing
    #the data from the table of 2014 Sochi winter olympics medal counts.  

    #The columns for this dataframe should be called 
    #'country_name', 'gold', 'silver', and 'bronze'.  

    #There is no need to  specify row indexes for this dataframe 
    #(in this case, the rows will automatically be assigned numbered indexes).

    #You do not need to call the function in your code when running it in the
    #browser - the grader will do that automatically when you submit or test it.
    #'''

    countries = ['Russian Fed.', 'Norway', 'Canada', 'United States',
                 'Netherlands', 'Germany', 'Switzerland', 'Belarus',
                 'Austria', 'France', 'Poland', 'China', 'Korea', 
                 'Sweden', 'Czech Republic', 'Slovenia', 'Japan',
                 'Finland', 'Great Britain', 'Ukraine', 'Slovakia',
                 'Italy', 'Latvia', 'Australia', 'Croatia', 'Kazakhstan']

    gold = [13, 11, 10, 9, 8, 8, 6, 5, 4, 4, 4, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]
    silver = [11, 5, 10, 7, 7, 6, 3, 0, 8, 4, 1, 4, 3, 7, 4, 2, 4, 3, 1, 0, 0, 2, 2, 2, 1, 0]
    bronze = [9, 10, 5, 12, 9, 5, 2, 1, 5, 7, 1, 2, 2, 6, 2, 4, 3, 1, 2, 1, 0, 6, 2, 1, 0, 1]

    # your code here
    olympic_medal_counts_df = DataFrame({'country_name' : Series(countries),
       'gold' : Series(gold),
       'silver':Series(silver),
       'bronze':Series(bronze)})

    return olympic_medal_counts_df

0 个答案:

没有答案