Python 关于熊猫的数据框问题

Python 关于熊猫的数据框问题,python,pandas,dataframe,series,Python,Pandas,Dataframe,Series,我正在解决一个关于熊猫数据帧的测验问题。但是我被卡住了。我写了代码,但没有给出结果。谁能给点建议?我的代码在“#你在这里编码”下面 你的代码对我有用。您是以交互方式运行它还是从文件运行它?也许您忘记调用create\u dateframe()?您的代码成功地创建了一个数据帧,如果没有关于问题要求的更多信息,就很难知道出了什么问题。我可以猜测,因为您使用字典创建数据框,所以列的顺序是错误的。。。此外,无需调用列表中的系列国家,黄金,白银,以及青铜,这是整个文件吗?文件末尾有空行吗?如果不是,有时在

我正在解决一个关于熊猫数据帧的测验问题。但是我被卡住了。我写了代码,但没有给出结果。谁能给点建议?我的代码在“#你在这里编码”下面


你的代码对我有用。您是以交互方式运行它还是从文件运行它?也许您忘记调用
create\u dateframe()
?您的代码成功地创建了一个数据帧,如果没有关于问题要求的更多信息,就很难知道出了什么问题。我可以猜测,因为您使用字典创建数据框,所以列的顺序是错误的。。。此外,无需调用列表中的系列
国家
黄金
白银
,以及
青铜
,这是整个文件吗?文件末尾有空行吗?如果不是,有时在某些平台上,最后一行代码会被忽略。嗨!你在上Udacity的课程,对吗?正如上面所有答案所指出的,您的代码是完全正确的。可能您的平台本身有问题(web浏览器??我不知道可能是什么)。我建议您使用Udacity论坛获取帮助或报告问题。祝你好运
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