Page 341 - Informatics_Practices_Fliipbook_Class12
P. 341

def displayData():
                 df = pd.read_csv('data.csv', names = ['NameofEvent', 'Nameofsportsperson',
                 'Category','MedalWon','Cashprize'],skiprows=1)
                displayMenu = '''     ----Display DATA MENU----

                                1: Display all records
                                2: Display some records from the top
                                3: Display some records from the bottom
                                4: Display records of selected columns only

                                5: Return to Main Menu'''


                while(True):

                    print(displayMenu)


                    choice = int(input("Enter Choice:"))



                    if choice == 1:
                        print(df)

                    elif choice == 2:
                        numTopRecords = int(input("How many records to display from top?:"))
                        print(df.head(numTopRecords))
                    elif choice == 3:

                        numBottomRecords =int(input("How many records to display from bottom?:"))
                        print(df.tail(numBottomRecords))

                    elif choice == 4:
                        print(df.columns)
                        columnList = []
                        while True:

                            columnName = input('\nEnter column name:')
                            if columnName not in df.columns:
                                print("Please enter valid column name")

                            else:
                                columnList.append(columnName)
                            wantMoreRecords = input('Do you want to give more column name (y/n):')

                            if wantMoreRecords not in 'yY':
                                break
                        print('Data for selected columns:')

                        print(df[columnList])


                                                                                                       Project   327
   336   337   338   339   340   341   342   343   344   345   346