Simple Join Of Two Data Frames In Pandas
I have two data frames in a Python program using Pandas. I am new to Pandas. Each one has a number of columns and rows - the first is similar to: calc_1 calc_2 calc_3 0 34.3
Solution 1:
Use pd.concat and pass axis=1 to concatenate column-wise:
In [37]:
pd.concat([df,df1], axis=1)
Out[37]:
calc_1 calc_2 calc_3 gender age
0 34.3 43.1 42.0 M 25
2 3.0 4.0 5.0 M 27
3 6.1 6.1 6.2 M 27
4 4.2 4.3 4.5 F 36
or join:
In [38]:
df.join(df1)
Out[38]:
calc_1 calc_2 calc_3 gender age
0 34.3 43.1 42.0 M 25
2 3.0 4.0 5.0 M 27
3 6.1 6.1 6.2 M 27
4 4.2 4.3 4.5 F 36
Or merge and set left_index=True and right_index=True:
In [41]:
df.merge(df1, left_index=True, right_index=True)
Out[41]:
calc_1 calc_2 calc_3 gender age
0 34.3 43.1 42.0 M 25
2 3.0 4.0 5.0 M 27
3 6.1 6.1 6.2 M 27
4 4.2 4.3 4.5 F 36
Post a Comment for "Simple Join Of Two Data Frames In Pandas"