Page 225 - Ai Book - 10
P. 225

df = pd.DataFrame(data, columns = [‘First Column Name’,’Second Column Name’,...])
              print (df)
        You should ensure that the column names specified in the code are similar to the column names mentioned in
        the Excel file. Suppose a sheet made on Excel is stored in the F:\ drive of your computer in the following format:
































        Let us understand how to import data of excel file in Python and assign it to the dataframe with the help of a
        simple example given below:

              import pandas as pd
              df = pd.read_excel(r’F:\Worksheet_Cyber.xlsx’)
              print (df)
        The output of the following code is shown in the snapshot given below:






















        Now, let us learn how to use head() function in the dataframes. The head() function is used to print the top 5
        rows of a list. The basic syntax of using head() function is:
              import pandas as pd
              df = pd.read_excel(r’F:\Worksheet_Cyber.xlsx’)
              print (df.head())





                                                                                                              99
                                                                                                              99
   220   221   222   223   224   225   226   227   228   229   230