combine dataframes with same columns code example
Example 1: merge two dataframes based on column
df_outer = pd.merge(df1, df2, on='id', how='outer')
df_outer
Example 2: pandas merge two columns from different dataframes
df_merge_col = pd.merge(df1, df2, on='id')
Example 3: How to join two dataframes by 2 columns so they have only the common rows?
import pandas as pd
import numpy as np
df1 = pd.DataFrame({'fruit': ['apple', 'banana', 'orange'] * 3,
'weight': ['high', 'medium', 'low'] * 3,
'price': np.random.randint(0, 15, 9)})
df2 = pd.DataFrame({'pazham': ['apple', 'orange', 'pine'] * 2,
'kilo': ['high', 'low'] * 3,
'price': np.random.randint(0, 15, 6)})
out = df1.merge(df2,left_on=('fruit','weight'),right_on=('pazham','kilo'),how='inner',suffixes=('_left','_right')).head(10)
Example 4: merge two dataframes based on column
df_merge_col = pd.merge(df_row, df3, on='id')
df_merge_col
Example 5: concact geodataframe python
>>> s1 = pd.Series(['a', 'b'])
>>> s2 = pd.Series(['c', 'd'])
>>> pd.concat([s1, s2])
0 a
1 b
0 c
1 d
dtype: object