Page 227 - Ai Book - 10
P. 227

Many times, you want to drop columns that are not required among the large data sets. An easy way to do it in
        the Excel file but if you forget to drop the unnecessary columns in Excel file, then you can write the following
        code in Python because Python provides an easy way to drop any unnecessary column using the built-in function
        drop():
              import pandas as pd
              df = pd.read_excel(r’F:\Worksheet_Cyber.xlsx’)
              df = df.drop([“Class”],axis=1 )
              print (df.head(20))
        The output of the above code is shown in the snapshot given below:
























        After dropping desired columns in an Excel sheet, we will learn how to sort the values of any column in a large
        dataset using Python code. Suppose, you have made a worksheet named Book_list that contains three columns.
        These columns are : S. No., Books, Price.
















        Now, you want to sort the list of items according to the price. To do so, you can write the following code:

              df = pd.read_excel(r’F:\Book_list.xlsx’)
              df = df.sort_values(by=’Price’,ascending = True)
              print (df.head())
        The output of the above code is shown in the snapshot given below:
















                                                                                                             101
                                                                                                             101
   222   223   224   225   226   227   228   229   230   231   232