0

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
asked Nov 21, 2014 at 13:31
1
  • Unless you call create_dataframe somewhere you aren't showing, there is no result from that script. Commented Nov 21, 2014 at 13:32

1 Answer 1

3

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.

Łukasz Rogalski
23.3k10 gold badges63 silver badges93 bronze badges
answered Nov 21, 2014 at 13:32
Sign up to request clarification or add additional context in comments.

1 Comment

adding the if name == "main": main() did the trick! Thank you, i will accept when i can in a few minutes

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.