Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

merge two dataframes with common columns

import pandas as pd
pd.merge(df1, df2, on="movie_title")
Comment

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)
Comment

merge two dataframes with common columns

dfinal = df1.merge(df2, how='inner', left_on='movie_title', right_on='movie_name')
Comment

Merge two data frames based on common column values in Pandas

import pandas
dfinal = df1.merge(df2, on="movie_title", how = 'inner')
Comment

PREVIOUS NEXT
Code Example
Python :: reset_index(drop=true) 
Python :: python run command 
Python :: how to run python program in sublime text 3 windows 
Python :: python pil 
Python :: calculate mean median mode in python 
Python :: python read file into variable 
Python :: python - find specific name in a df 
Python :: if main 
Python :: python dictionary default 
Python :: check if year is leap python 
Python :: cv2 copy image 
Python :: how to make a nan value in a list 
Python :: create a dataframe from dict 
Python :: python working directory 
Python :: python if condition assignment in one line 
Python :: Calculate Euclidean Distance in Python using norm() 
Python :: python series 
Python :: run in thread decorator 
Python :: extract email address using expression in django 
Python :: change django administration text 
Python :: Mittelwert python 
Python :: fillna with median , mode and mean 
Python :: python while true loop 
Python :: stack concatenate dataframe 
Python :: regex remove all html tags except br python 
Python :: python filter dict 
Python :: get every item but the last item of python list 
Python :: python print without new lines 
Python :: django authenticate 
Python :: the python libraries to master for machine learning 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =