This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 3: DataFrame

Examining the DataFrame

face Josiah Wang

So far, you used the attributes like df.shape, df.columns, and df.index to examine the DataFrame.

Pandas actually provides even more convenient methods to examine the DataFrame. Try these three methods yourselves!

  • df.head(n): Get the top n rows. What is the return type of this method? What is the default n?
  • df.tail(n): Get the last n rows. What is the return type of this method? What is the default n?
  • df.info(): Prints some useful information about the index and columns of the DataFrame.
  • df.describe(): Prints out some summary statistics (like mean, std, etc.) for any numeric columns of the DataFrame.

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()
????