Answers for "combine 2 data frames in oython"

9

combining 2 dataframes pandas

df_3 = pd.concat([df_1, df_2])
Posted by: Guest on May-13-2020
0

merge two df

bigdata = pd.concat([data1, data2], ignore_index=True, sort=False)
Posted by: Guest on July-07-2020
0

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)
Posted by: Guest on June-04-2020

Code answers related to "combine 2 data frames in oython"

Python Answers by Framework

Browse Popular Code Answers by Language