简体   繁体   中英

SQL “WHERE IN” equivalent in Pandas

I'm trying to extract all indices that have the value "US" and "JP" in column "Country"

Main_table

Date         Country   Customer_id
2019-01-01   UK        434393
2019-01-01   UK        553334
2019-01-01   US        424292
2019-01-01   JP        433535

Output table

Index:3,4

This is what I've tried so far, but I get zero results:

indexNames = df[ (df['Country'] == 'US') & (df['Country'] == 'JP') ].index

Change & to |

indexNames = df[ (df['Country'] == 'US') | (df['Country'] == 'JP') ].index

Or just isin

indexNames = df[ (df['Country'].isin(['US', 'JP']) ].index

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