Reputation: 3617
I am really new to python and have what i believe to be a very simple question. I have the python script goldmedal.py and i want to return the result of the this script to the command line.
I have been searching but i can not seem to find a straight forward answer. When i run goldmedal.py i want to show the return olympic_medal_counts_df into the command line. What should i add to the code so it returns the variable back to the command line.
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
Upvotes: 0
Views: 235
Reputation: 117876
Create a python file, save it with a .py
extension.
Then create a main
function
def main():
df = create_dateframe() # Note you need to call your other function
print(df)
if __name__ == "__main__":
main()
Then run the python script from the command prompt.
Upvotes: 3