Original
pandas convert dictionary to DataFrame
Convert dict d = {'A':0}
to DataFrame,
first of all, the syntax format of DataFrame should be:
import pandas as pd
df = pd.DataFrame({'A':[0]})#'A'是columns,对应的是list
- 1
- 2
output:
A
0 0
- 1
- 2
But if it is:
df = pd.DataFrame({'A':0})#直接输入dict
- 1
will report an error
ValueError: If using all scalar values, you must pass an index
- 1
Solution 1:
Specify index
pd.DataFrame({'A':0},index=[0])
- 1
Solution 2:
Put the dictionary in a list
pd.DataFrame([{'A':0},{'A':1}])
- 1
output:
A
0 0
1 1