sql-function

How to filter Pandas dataframe using 'in' and 'not in' like in SQL

How to filter Pandas dataframe using 'in' and 'not in' like in SQL Question: How can I achieve the equivalents of SQL’s IN and NOT IN? I have a list with the required values. Here’s the scenario: df = pd.DataFrame({‘country’: [‘US’, ‘UK’, ‘Germany’, ‘China’]}) countries_to_keep = [‘UK’, ‘China’] # pseudo-code: df[df[‘country’] not in countries_to_keep] My …

Total answers: 11