When you create series with a dictionary, the keys are taken as index and values are, well, values. So,
pd.Series(sdata)
would give you:
a 3
b 5
c 8
d -2
dtype: int64
Now, if in addition, you pass index
to pd.Series(some_dict)
it is equivalent to a reindex
:
pd.Series(sdata).reindex(states)
and since states
doesn't contains any keys in sdata
, you get a series indexed by states
and contains all NaN
.
If you are certain about the order, you can create the series with:
pd.Series(list(sdata.values()), index=states)
Output:
place1 3
place2 5
place3 8
place4 -2
dtype: int64
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…