How to Create an Empty Dataframe in Python

To create an empty dataframe in Python, you can use the pandas.DataFrame() function.

The following example shows how to create an empty dataframe in Python.

Using pandas.DataFrame() Function

We can use the pandas.DataFrame() function to create an empty dataframe.

Let’s see how to use the pandas.DataFrame() function in Python:

import pandas as pd

# Create empty dataframe
df = pd.DataFrame()

# Show dataframe
print(df)

Output: 👇️

Empty DataFrame
Columns: []
Index: []

The output shows the empty dataframe created using the pandas.DataFrame() function.

You can also create an empty dataframe with column names. Let’s see how to do that:

# Import pandas library
import pandas as pd

# Create empty dataframe with column names
office_stuff = pd.DataFrame(columns=['Date', 'Product_Code', 'Product_Name', 'Price', 'Status'])

# Show empty dataframe
print(office_stuff)

Output: 👇️

Empty DataFrame
Columns: [Date, Product_Code, Product_Name, Price, Status]
Index: []

As the output shows, an empty dataframe is created with column names but without rows.

Conclusion

We can use the pandas.DataFrame() function to create an empty dataframe in Python.