首页 > 解决方案 > combine dataframes in pandas with repeat slices of one of them

问题描述

I want to combine 2 dataframes.

Here are the samples of dataframes:

df1:

linktoDF1

enter image description here

df2:

linkdoDF2

enter image description here

Desired output should be:

linktoResultcsv

enter image description here

What I want in essence is to extend df1 with data from df2. Key to linking data is index of both dataframes which is ['latitude','level','longitude']. I want to omit data with index unique to df2. i.e. I don't want to see data with index [41, 1000, 19.25 ] Any help is appreciated.

标签: pythonpandasdataframe

解决方案


Use "merge" with how='left', which omits indexes not in df1:

rslt= pd.merge(df1,df2,on=["latitude","level","longitude"],how="left")

推荐阅读