I have 2 Pandas series:
First
A 91
P 7
F 281
M 54
Second
A 107
P 3
F 290
M 51
I want to combine them so they look like this:
A 91 107
P 7 3
F 281 290
M 54 51
With null if index not found.
I have 2 Pandas series:
First
A 91
P 7
F 281
M 54
Second
A 107
P 3
F 290
M 51
I want to combine them so they look like this:
A 91 107
P 7 3
F 281 290
M 54 51
With null if index not found.
You can use a simple pd.concat
for this:
pd.concat([df1,df2], axis = 1)
First Second
A 91 107
P 7 3
F 281 290
M 54 51
This will set to NaN
the values from rows with non-shared index, given that by default it performs an outer join. Here's an example:
print(df1)
First
A 91
P 7
D 4
F 281
M 54
print(df2)
Second
A 107
P 3
F 290
M 51
X 20
pd.concat([df1,df2], axis = 1, sort=False)
First Second
A 91.0 107.0
P 7.0 3.0
D 4.0 NaN
F 281.0 290.0
M 54.0 51.0
X NaN 20.0