Introduction to Pandas
Chapter 3: DataFrame
Examining the DataFrame
So far, you used attributes like df.shape, df.columns, and df.index to examine the DataFrame.
Pandas actually provides more convenient methods to examine the DataFrame. Try these three methods yourselves!
df.head(n): Get the topnrows. What is the return type of this method? What is the defaultn?df.tail(n): Get the lastnrows. What is the return type of this method? What is the defaultn?df.info(): Prints some useful information about the index and columns of theDataFrame.df.describe(): Prints out some summary statistics (like mean, std, etc.) for any numeric columns of theDataFrame.
Read the documentation if you need further information!
Task
Try printing out the first 20 Pokemons and the last 10 Pokemons!
>>> df.head()
????
>>> df.head(20) # Print out the first 20 Pokemons
????
>>> print(type(df.head())) # This returns another DataFrame!
<class 'pandas.core.frame.DataFrame'>
>>> df.tail()
>>> df.tail(10) # Print out the last 10 Pokemons
>>> print(type(df.tail()))
<class 'pandas.core.frame.DataFrame'>
>>> df.info()
????