Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

DataFrame from Dictionary

  1. By default each key-value is a column in the resulting data frame. You can specify the option orient = 'index' to make each key-value a row in the resulting data frame when using the method pandas.DataFrame.from_dict.

  2. Starting from Python 3.7, a dict preserves insertion orders. This effectively makes a pandas DataFrame keep the insertion order of columns.

Loading...
Loading...
Loading...
Loading...

DataFrame from List of Dictionaries (as Rows)

Each dictionary is a row in the resulting data frame.

Loading...

DataFrame from List of Lists/Tuples (as Rows)

Each list/tuple is a row in the resulting data frame.

Loading...
Loading...

DataFrame from List of Lists/Tuples (as Columns)

Each list/tuple is a row in the resulting data frame. Note that pd.concat on a list of Lists/Tuples won’t here. You have to first create a DataFrame with the list of Lists/Tuples as rows and then transpose it.

Loading...

DataFrame from One Series (as a Row)

The sereis is a row in the resulting data frame.

Loading...
Loading...

DataFrame from Multiple Serieses (as Rows)

The sereises are rows in the resulting data frame.

Loading...

DataFrame from One Series (as a Column)

The sereis is a column in the resulting data frame.

Loading...
Loading...

DataFrame from Multiple Series (as Columns)

The serieses are columns in the resulting data frame.

Loading...

Series to Underlying Data

[1, 2, 3, 4, 5]

DataFrame to Underlying Data

   a  x
0  5  1
1  4  2
2  3  3
3  2  4
4  1  5
[[5, 1], [4, 2], [3, 3], [2, 4], [1, 5]]

Index

An index will always be created. By default, a sequence of integers (starting from 0) is used as the index.

Loading...

Column Names

Similar to the index, a sequence of integers (starting from 9) is used as the column names by default.

Loading...

Empty DataFrame

Create an empty DataFrame without any column or row.

Loading...

Create an empty (no rows) DataFrame with 1 column named x.

Loading...

Create an empty (no rows) DataFrame with 2 column x and y.

Loading...

You can use the variable DataFrame.empty to check whether a DataFrame is empty or not.

True

You can operate on columns of an empty (no rows) DataFrame as usual.

Loading...
0
NaT
True
True
0