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.

Related Posts

  • 20 September

    Reorder the columns of pandas dataframe in Python

    In this post, we will see 3 different methods to Reordering the columns of Pandas Dataframe : Using reindex method You can use DataFrame’s reindex() method to reorder columns of pandas DataFrame. You need to pass columns=[$list_of_columns] to reindex() method to reorder columns of Pandas DataFrame. [crayon-6009088420eff211577129/] Output : Given Dataframe : Name Gender Age […]

  • 08 September

    Pandas create Dataframe from Dictionary

    In this tutorial, We will see different ways of Creating a pandas Dataframe from Dictionary . Using a Dataframe() method of pandas. Example 1 : When we only pass a dictionary in DataFrame() method then it shows columns according to ascending order of their names . [crayon-600908840d4dd800796592/] Output : [crayon-600908840d4e1623631157/] Example 2 : If we […]

  • 08 September

    Pandas Convert list to DataFrame

    In this tutorial, We will see different ways of Creating a pandas Dataframe from List. You can use Dataframe() method of pandas library to convert list to DataFrame. so first we have to import pandas library into the python file using import statement. So let’s see the various examples on creating a Dataframe with the […]

  • 26 May

    Pandas DataFrame to CSV

    In this post, we will see how to save DataFrame to a CSV file in Python pandas. You can use DataFrame.to_csv() to save DataFrame to CSV file. We will see various options to write DataFrame to csv file. Syntax of DataFrame.to_csv() [crayon-6009088421072814961301/] Here, path_or_buf: Path where you want to write CSV file including file name. […]

  • 26 May

    Pandas convert column to float

    In this post, we will see how to convert column to float in Pandas. Convert String column to float in Pandas There are two ways to convert String column to float in Pandas. Using asType(float) method You can use asType(float) to convert string to float in Pandas. Here is the syntax: [crayon-600908842130e488814064/] Here is an […]

  • 26 May

    How to install Pandas in Python

    Installing Python pandas on Windows Prerequisites: Check If python is installed on your system, If yes then you should be able to get its version using command prompt: e.g. C:\Users\dipanshuasri>python –version Python 3.8.2 If not installed then please visit https://www.python.org/downloads/ Python Pandas can be installed on windows in 2 ways: Using Pip (package manager) Using […]

Leave a Reply

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

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.