Here’s how to create Pandas empty dataframe in Pandas Python library.
How to create an empty dataframe in Pandas
To create an empty Pandas DataFrame, you can use the pd.DataFrame() constructor with no arguments. This creates a dataframe with 0 rows and 0 columns.
import pandas as pd my_df = pd.DataFrame() print(my_df)
The output of a print function is:
Empty DataFrame Columns: [] Index: []
As you may notice, the dataframe you created is completely empty.
How to create an empty dataframe with specific shape
If you want to create an empty dataframe with specified columns, you can pass a dictionary with empty lists or numpy arrays as values:
my_df = pd.DataFrame({"column_1": [], "column_2": []})
Alternatively, you can pass a list of tuples, where each tuple is a row in the dataframe:
my_df = pd.DataFrame([], columns=["column_1", "column_2"])
Creating an empty Pandas DataFrame can be done using the pd.DataFrame() constructor with no arguments. This will create an empty DataFrame with no columns or rows. If you need to create a DataFrame with a specific number of rows and columns, you can pass the desired dimensions as arguments to the constructor.
1 thought on “How to create Pandas empty dataframe”