concatenating datfra,esin pandas code example

Example 1: pandas left join

df.merge(df2, left_on = "doc_id", right_on = "doc_num", how = "left")

Example 2: how to merge two dataframes

df_merge_col = pd.merge(df_row, df3, on='id')

df_merge_col

Example 3: how to concat on the basis of particular columns in pandas

In [6]: result = pd.concat(frames, keys=['x', 'y', 'z'])

Example 4: concatenating datfra,esin pandas

In [8]: df4 = pd.DataFrame({'B': ['B2', 'B3', 'B6', 'B7'],
   ...:                     'D': ['D2', 'D3', 'D6', 'D7'],
   ...:                     'F': ['F2', 'F3', 'F6', 'F7']},
   ...:                    index=[2, 3, 6, 7])
   ...: 

In [9]: result = pd.concat([df1, df4], axis=1, sort=False)

Tags:

Misc Example