Page 226 - Ai Book - 10
P. 226
The output of the following code is shown below:
Suppose you have an Excel sheet that contains 100 rows of data and you want to print only 20 rows. In such
a case, you can pass the number of rows as a parameter in the head() function. The basic syntax to print the
desired number of rows among the large datasets is:
print(dataframe.head(20))
Let us understand the concept of parametrized head function with the help of an example given below:
import pandas as pd
df = pd.read_excel(r’F:\Worksheet_Cyber.xlsx’)
print (df.head(20))
The output of the above code is as follows:
Data type plays an important role while declaring variables in any programming language. In Python, data type
declaration of variable is not required because Python is completely object oriented. But, sometimes you want
to determine the data type of variable. To do so, you can write the following lines of code:
import pandas as pd
df = pd.read_excel(r’F:\Worksheet_Cyber.xlsx’)
print (df.dtypes)
Here, dtypes is used to determine the data types of the defined columns.
The output is:
100
100