0

Here is how it looks like:

dictionary = { '1' : 'mine.csv' , '2' : 'yours.csv' , '3' : 'ours.csv' ...}

I want to ask user input :

def get_filters():

question = input('which file would you like to view its contents ?' , 1)

so answer should be like : '1' >> it opens first file from dictionary to start filter.

I want all files to open from a single code :

def load_data(question, ..):
    df= pd.read_csv(dictionary[question]) 

since df is going to be used in filtering all data inside files.

but this does not load file , and program consider filtering output as tuples.

How to connect dictionary key and value to load data , like: if input is key : load value . Or simple other ways to do it?

  • 'but this does not load file , and program consider filtering output as tuples.' --- can you show more details of current behaviou? – Lei Yang Feb 22 '22 at 03:11

1 Answers1

0

I am not 100% sure I understand the question, but you could use something like this:

def load_data():
    while True:
        question = input('which file would you like to view its contents ?')
        try:
            df = pd.read_csv(dictionary[question])
            return df
        except Exception as e:
            print(e)

This will take a user input, attempt to open a file. If it succeeds, it will return the df. If it fails, it will print the error and then let the user try again.