将 Pandas 系列插入 DataFrame 使所有值都为 Nan

Inserting a Pandas Series into a DataFrame makes all values Nan

正如标题所暗示的那样,我已经将两个词典转换成这样的系列,并且我试图将它们插入到数据框 df 中。

first_series = pd.Series(first_dict, name='State Names')
second_series = pd.Series(second_dict, name='City Names')
column_loc=list(df.columns.values).index("ipAddr")
df.insert(column_loc+1, 'State Names', first_series)
df.insert(column_loc+2, 'City Names', second_series)

当我 运行 然而我得到

              ipAddr State Names City Names    ...       
respID                                         ...        
10018         ***.**.**.**  NaN        NaN     ...        
10025         **.**.**.**   NaN        NaN     ...       

系列如下

10018       Bedford
10025     Vancouver
        ...    
10267        Lompoc
10280    Pikesville
Name: State Names, dtype: object
--------------------------------------------------------
10018          Ohio
10025    Washington
        ...    
10267    California
10280      Maryland
Name: City Names, dtype: object

我已经检查过字典和生成的系列都已填充,所以我不明白为什么会这样。

谢谢。

编辑:这里有人问过类似的问题,但没有得到回答 When I insert pandas Series into dataframe, all values become NaN

原来系列的行数比 df 少。此外, Series.values 需要在将其分配给 df 列时使用。