> ## Content Index
> Fetch the complete content index at: https://datascientyst.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Create Empty DataFrame in Pandas
- URL: https://datascientyst.com/create-empty-dataframe-pandas/
- Published: 2021-12-17T22:33:31.000Z
- Updated: 2021-12-17T22:33:31.000Z
- Author: John D K
- Tags: Create

## 1\. Overview

This short article describes **how to create empty DataFrame in Pandas.**

Generally, there are three options to create empty DataFrame:

- Empty DataFrame
- Empty DataFrame with columns
- Empty DataFrame with index and columns

In general it's not recommended to create empty DataFrame and append rows to it.

## 2\. Create Empty DataFrame

Let's start by creating completely empty DataFrame:

- no data
- no index
- no columns

The constructor called without any parameters as:

```python
import pandas as pd

df = pd.DataFrame()

```

Will create a DataFrame object that doesn't have data and attributes. If you print it, you will get:

```
Empty DataFrame
Columns: []
Index: []

```

To append rows and add columns to empty DataFrame - you can use bracket notation and assign values to it.

So in brackets we have the column name and the lists contains the row values:

```python
df['Rank'] = ['silver', 'gold', 'gold']
df['score'] = [54, 75, 87]

```

Now the result will be:

|   | Rank   | score |
| - | ------ | ----- |
| 0 | silver | 54    |
| 1 | gold   | 75    |
| 2 | gold   | 87    |

## 3\. Create Empty DataFrame with index and columns

What if you like to make **DataFrame without data - only with index and columns**. The DataFrame constructor needs two parameters: `columns` and `index`:

```python
import pandas as pd

df = pd.DataFrame(columns = ['Score', 'Rank'],
                   index = ['James', 'Jim'])

```

our DataFrame without any data looks like:

|       | Score | Rank |
| ----- | ----- | ---- |
| James | NaN   | NaN  |
| Jim   | NaN   | NaN  |

To set data for any of the existing rows we can use property `loc` which is described as:

> Access a group of rows and columns by label(s) or a boolean array.

To set values for Jim we can do:

```python
df.loc['Jim'] = [50, 'gold']

```

result:

|       | Score | Rank |
| ----- | ----- | ---- |
| James | NaN   | NaN  |
| Jim   | 50    | gold |

## 4\. Create Empty DataFrame with column names

To **create a DataFrame which has only column names** we can use the parameter `column`. We are using the DataFrame constructor to create two columns:

```python
import pandas as pd

df = pd.DataFrame(columns = ['Score', 'Rank'])
print(df)

```

result:

```
Empty DataFrame
Columns: [Score, Rank]
Index: []

```

If you display it you will get:

|  | Score | Rank |
|  | ----- | ---- |

To append rows to this DataFrame we can use method [append()](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.append.html?ref=datascientyst.com) and provide dictionary with values:

```python
df.append({'Score' : '68', 'Rank' : 'gold'}, ignore_index = True)

```

Result is:

|   | Score | Rank |
| - | ----- | ---- |
| 0 | 68    | gold |

Parameter `ignore_index` is used in order to avoid error:

> TypeError: Can only append a dict if ignore\_index=True

## 5\. Efficient way to append rows to DataFrame

And the way above is not very efficient for multiple rows. A better approach to append rows to empty DataFrame is by method [concat()](https://pandas.pydata.org/docs/reference/api/pandas.concat.html?ref=datascientyst.com#pandas.concat):

So in order to append multiple rows to empty or full DataFrame `df` like:

|       | Score | Rank |
| ----- | ----- | ---- |
| James | NaN   | NaN  |
| Jim   | 50    | gold |

is by concatenating the two DataFrames:

```python
df_a = pd.DataFrame({'Score' : ['68', '5'], 'Rank' : ['gold', 'zero']}, index=['Joe', 'Jery'])

pd.concat([df, df_a])

```

result:

|       | Score | Rank |
| ----- | ----- | ---- |
| James | NaN   | NaN  |
| Jim   | 50    | gold |
| Joe   | 68    | gold |
| Jery  | 5     | zero |

## 6\. Conclusion

And now we're able to create empty DataFrame in several ways. We looked at how to add data, index and columns. We covered more efficient way of doing it.

Now you know more about DataFrame and how you can add rows and data to it.