Pandas – Create an Empty DataFrame

Pandas – Create an Empty DataFrame

In Pandas, you can create an empty DataFrame using pandas.DataFrame() constructor. Call the DataFrame() constructor and pass no arguments to it. The constructor returns an empty DataFrame with zero rows and zero columns.

In this tutorial, we shall go through examples on how to create an empty DataFrame.

1. Create an empty DataFrame using pandas.DataFrame() constructor

In this example, we need to create an empty DataFrame, and print it to standard console output.

Steps

  1. Import pandas library.
  2. Call DataFrame() constructor of pandas library. It returns an empty DataFrame. You may store it in a variable.
  3. Print the empty DataFrame to console output.

Program

The complete program to create an empty DataFrame is given below.

Python Program

import pandas as pd

# Create an empty DataFrame
df_empty = pd.DataFrame()

print(df_empty)
Run Code Copy

Output

Empty DataFrame
Columns: []
Index: []

2. Create empty DataFrame by passing empty dictionary to pandas.DataFrame()

We can also pass an empty dictionary as argument to DataFrame(), which return an empty DataFrame, same as in the previous example.

Steps

  1. Import pandas library.
  2. Take an empty dictionary in input.
  3. Call DataFrame() constructor of pandas library, and pass an empty dictionary input as argument. It returns an empty DataFrame since there is no data in the given dictionary. You may store it in a variable.
  4. Print the empty DataFrame to console output.

Program

The complete program to create an empty DataFrame by passing an empty dictionary to DataFrame() is given below.

Python Program

import pandas as pd

# Input dictionary
input = dict()

# Create an empty DataFrame
df_empty = pd.DataFrame(input)

print(df_empty)
Run Code Copy

Output

Empty DataFrame
Columns: []
Index: []

Summary

In this Pandas Tutorial, we learned how to create an empty DataFrame using pandas.DataFrame() constructor, with example programs.

Related Tutorials

Code copied to clipboard successfully 👍