I have a program that has multiple functions defined by
And so on. These are accessed through a menu defined here:
menu() option = int(raw_input("Select an option: ")) while option != 0: if option == 1: function_1(df) elif option == 2: function_2(df) elif option == 3: function_3(df) elif option == 4: function_4(df) else: print("This option is not valid.") menu() option = int(input("Select option: ")) print("Thanks for using program.")
The menu looks like this:
def menu(): print(": 1st Function") print(": 2nd Function") print(": 3rd Function") print(": 4th Function") print(": Modify the year to analyse") print(": Quit Program")
I have 3 files that I have are named as followed:
I need to find a way for the program to ask (at the start of the program) for a year between 2000, 2010 or 2020 and for the program to read the file for that year, using something like: df = pd.read_csv(‘2010.rep.csv’).
I also need the program to offer the option to change the year through the menu if needed (so read a different file if needed).
I have tried multiple things but I can’t get any to work, I just need a bit of help as python is new to me. Any help is appreciated.
Using Python 2.7 and Pandas 0.24.2
Make an option, just like what you did.
def select_year(): print('2000') print('2010') print('2020') select_year() year = str(raw_input('Please select a year: ')) # If year is not in list while not year in ['2000','2010','2020']: print('Year is not valid') select_year() year = str(raw_input('Please select a year: ')) df = pd.read_csv(year + '.rep.csv')