我對python真的很陌生,有我認爲是一個非常簡單的問題。我有python腳本goldmedal.py,我想把這個腳本的結果返回給命令行。在Windows命令行中顯示python return
我一直在尋找,但我似乎無法找到一個簡單的答案。當我運行goldmedal.py我想要顯示返回olympic_medal_counts_df到命令行。我應該添加到代碼中,以便將變量返回到命令行。
from pandas import DataFrame, Series
def create_dataframe():
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]
d = {'countries': Series(countries), 'gold': Series(gold), 'silver':Series(silver), 'bronze': Series(bronze)}
olympic_medal_counts_df = DataFrame(d)
return olympic_medal_counts_df
除非你在你沒有顯示的地方調用*'create_dataframe',否則這個腳本沒有結果。 – jonrsharpe 2014-11-21 13:32:18