Pandas | Create empty DataFrame in Python

In this post, we will see how to create empty dataframes in Python using Pandas library.

Suppose you want to just create empty dataframe, and put data into it later. Let’s see how to create empty dataframe in different ways.

DataFrame is tabular data structure similar to spreadsheets. It contains ordered collections of columns , and each column has data type associated with it.

DataFrame class provides a constructor to create a dataframe using multiple options.

Here,
data: It can be any ndarray, iterable or another dataframe.
index: It can be an array, if you don’t pass any index, then index will range from 0 to number of rows -1
columns: Columns are used to define name of any column
dtype: dtype is used to force data type of any column. If you don’t specify dtype, dtype is calculated from data itself.

Create empty dataframe

If you just want to create empty dataframe, you can simply use pd.DataFame().

Here is an example:

Output:

Empty DataFrame
Columns: [] Index: []

Append data to empty dataframe

You can append data to empty dataframe as below:

Output:

Create empty dataframe with columns

If you also know columns of dataframe but do not have any data, you can create dataframe with column names and no data.
Let’s see how to do it.

Output:

Empty DataFrame
Columns: [Name, Age, Gender] Index: []

Append data to empty dataframe with columns

You can append data to empty dataframe with columns as below:

Output:

Create empty dataframe with columns and indices

You can extend preceding example by adding indices to the rows as below:

Output:

Append data to empty dataframe with columns and indices

You can add rows with empty dataframe with existing index as below:

Output:

Create empty dataframe with indices

You can extend preceding example by adding indices to the rows as below:

Output:

Append data to empty dataframe with indices

You can add rows with empty dataframe with existing index as below:

Output:

That’s all about how to create empty dataframes in Python using Pandas.

Was this post helpful?

Leave a Reply

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