Create Empty pandas DataFrame in Python (2 Examples)

 

In this Python article you’ll learn how to initialize an empty DataFrame using the pandas library.

The tutorial contains the following content blocks:

Let’s do this…

 

Example 1: Create Empty pandas DataFrame without Column Names

Example 1 illustrates how to construct a pandas DataFrame with zero rows and zero columns.

As a first step, we have to load the pandas library to Python:

import pandas as pd                                  # Load pandas

Next, we can use the DataFrame() function to create an empty DataFrame object:

data_1 = pd.DataFrame()                              # Create empty DataFrame
print(data_1)                                        # Print empty DataFrame
# Empty DataFrame
# Columns: []
# Index: []

Have a look at the previous console output: We have created a pandas DataFrame with zero rows and no variables.

 

Example 2: Create Empty pandas DataFrame with Column Names

Example 2 explains how to initialize a pandas DataFrame with zero rows, but with predefined column names.

For this, we have to use the columns argument within the DataFrame() function as shown below:

data_2 = pd.DataFrame(columns = ["x1", "x2", "x3"])  # Create empty DataFrame with column names
print(data_2)                                        # Print empty DataFrame with column names
# Empty DataFrame
# Columns: [x1, x2, x3]
# Index: []

The previous output shows that we have created an empty data matrix with the three column names x1, x2, and x3.

 

Video, Further Resources & Summary

Have a look at the following video which I have published on my YouTube channel. I show the examples of this tutorial and give you some extra information on the topic:

 

 

Erik Marsja has recently released a video on his YouTube channel, which shows Python syntax for the creation of pandas DataFrames. You may check out the video to get more information on how to handle data tables in the Python programming language. Please find the video below.

 

 

Furthermore, you might read some of the related tutorials that I have published on this website.

 

To summarize: In this Python tutorial you have learned how to create an empty pandas DataFrame. If you have additional questions, please let me know in the comments. Furthermore, please subscribe to my email newsletter in order to receive updates on new tutorials.

 

Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Top