samedi 29 décembre 2018

While and if looping with pandas

I'm having problems to understand where is my mistake. I'm trying to get an input from the user > if "yes" - show some data from a DataFrame > if "no" keep going with the program.

Inside of if "yes" there's another question "Do you want more data?", and once again > if "yes" keep showing > if "no" leave both loops and continue with the program.

def display_data(df):
        n = 0
        raw_in = input('\nWould you like to see some raw data? yes or no.\n').lower()
        if raw_in in ['yes','no']:
            if raw_in == 'yes':
                raw_data = df.iloc[n:n+5,:]
                n += 5
                print(raw_data)
                raw_in = input('\nMore data? yes or no.\n').lower()
                if raw_in not in ['yes','no']:
                    print('\nInvalid option.\n')
                    display_data(df)
                else:
                    pass

That's what I've tried. I keep changing from while to if or their position, but I don't find the solution.

Aucun commentaire:

Enregistrer un commentaire