Update to 2018.5.1
Dictionary to generate DataFrame
Today a dictionary generates a DataFrame in the following form, each value is a number (not a vector)
df = pd.DataFrame({
'id': data_speed.index,
'Mileage':data_speed['count']*data_speed['mean'],
'SpeedAve':data_speed['mean'],
'SpeedStd':data_speed['std'],
'SpeedMax':data_speed['max'],
'HeightAve':data_height['mean'],
'HeightStd':data_height['std'],
})
The result broke the following error
ValueError: If using all scalar values, you must pass an index
It turns out that you can use a dictionary to generate a DataFrame, {'A':[ 'a'], 'B': ['b']}
but of course it doesn't have to be like this, so three methods can be successful: Quote
from: Statistician's Python Diary: Supplement on the Fourth Day The
first: {'A ':['a'], 'B': ['b']}
>>> df = pd.DataFrame({'A': ['a'], 'B': ['b']})
>>> df
A B
0 a b
The second: pass in the index index
>>> df = pd.DataFrame({'A': 'a', 'B': 'b'}, index=[0])
>>> df
A B
0 a b
The third type: DataFrame([dict])
>>> df = pd.DataFrame([{'A': 'a', 'B': 'b'}])
>>> df
A B
0 a b