Q: 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()
        while 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.

A: You do not need your while condition to check for 'no'. Seems that you want 'no' to stop the execution. Since you only need while raw_in == 'yes', you won't need the subsequent if statement either. Also, else, pass doesn't really serve a purpose.
def display_data(df):
    n = 0
    raw_in = input('\nWould you like to see some raw data? yes or no.\n').lower()
    while 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)

