我有一个数据框和一个维度不同的系列
from pandas import *
df = DataFrame({'a':[1,2,3],'b':[1,2,3]})
s = Series([1,2,3,4,5])
有没有一种方法可以在不先创建重新索引的df
副本的情况下将s
插入到df
中?目前我正在使用
df = df.reindex(range(len(s))
df['s'] = s
print df
a b s
0 1 1 1
1 2 2 2
2 3 3 3
3 NaN NaN 4
4 NaN NaN 5