If df
is a pandas.DataFrame
then df['new_col']= Series list_object of length len(df)
will add the or Series list_object as a column named 'new_col'
. df['new_col']= scalar
(such as 5 or 6 in your case) also works and is equivalent to df['new_col']= [scalar]*len(df)
So a two-line code serves the purpose:
df = pd.DataFrame({'a':[1, 2], 'b':[3, 4]})
s = pd.Series({'s1':5, 's2':6})
for x in s.index:
df[x] = s[x]
Output:
a b s1 s2
0 1 3 5 6
1 2 4 5 6