python - pandas DataFrame add a new column and fillna -
I am trying to add a column to a pdf data frame, such as:
Df = 'Pd.DataFrame') ['A'] = PD. Print (DF) df ['two'] = pd.Series ({'0': 4, '2': 6}) Print (DF) This yield:
one two 1 4 NaN 2 6 6
However, I could have the result,
A two 0 NaN 4 1 4 NaN 2 6 6
How do you do this?
You can join
want to do this:
df = pd.DataFrame () df ['one'] = pd.Series ({'1': 4, '2': 6}) df.join (Pd.Series ({'0' : 4, '2': 6}, name = 'two'), how = 'outer')
The result of
A two nan 4 1 4 nan 2 6 6
Comments
Post a Comment