简体   繁体   中英

How to perform inner join in multiple columns in pandas

I have 2 dataframe namely accidents_data which has 15 columns and bad_air_quality_data dataframe whch has 5 columns.

Now i'd like to inner join both data frames on column ['District Name', 'Weekday', 'Hour', 'Month'] and finally keep only the data from accidents_data after joining.

accidents_data:

accidents_data

bad_air_quality_data:

bad_air_quality_data

I tried merging both the dataframes using the below line but it does not show any results.

accidents_data_bad_air = pd.merge(accidents_data, bad_air_quality_data, on=['District Name', 'Weekday', 'Month', 'Hour'], how='inner')

I think i figured out the solution. While merging the data the datatype of same columns were different. After making that correction, the merge worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM