How to print the whole Dataframe in Python

In this tutorial, we will show you how to print the whole DataFrame using Python

Updated March 29, 2023

A DataFrame is a 2-dimensional labeled data structure with columns of potentially different types. In this tutorial, we will show you how to print the whole DataFrame using Python.

Method 1: Using the print() Function

The simplest way to print the whole DataFrame is to use the print() function. Here’s an example:

# Using the print() function
import pandas as pd

df = pd.read_csv('data.csv')

print(df)

In this code, we use the pandas library to read a CSV file and store it in a DataFrame called df. We then use the print() function to print the whole DataFrame.

Method 2: Using the display() Function

Another way to print the whole DataFrame is to use the display() function from the IPython.display module. Here’s an example:

# Using the display() function
import pandas as pd
from IPython.display import display

df = pd.read_csv('data.csv')

display(df)

In this code, we use the pandas library to read a CSV file and store it in a DataFrame called df. We then use the display() function to print the whole DataFrame.

Method 3: Using the head() Method

If your DataFrame is too large to print the whole thing, you can use the head() method to print the first few rows. Here’s an example:

# Using the head() method
import pandas as pd

df = pd.read_csv('data.csv')

print(df.head())

In this code, we use the pandas library to read a CSV file and store it in a DataFrame called df. We then use the head() method to print the first five rows of the DataFrame.

Conclusion

In this tutorial, we have shown you three different methods to print the whole DataFrame in Python. We have covered using the print() function, the display() function, and the head() method.

Remember that the print() function and display() function will print the whole DataFrame, while the head() method will print only the first few rows. Use the method that suits your needs and the context in which you’re working.

Keep practicing and have fun with Python programming!

Hey! Do you love Python? Want to learn more about it?
Let's connect on Twitter or LinkedIn. I talk about this stuff all the time!