如何根据 pandas 中的列值(国家/地区)过滤数据框

how to filter a data frame based on a column value (country) in pandas

我有一个大数据框,我想根据 COUNTRY 列过滤它。我需要来自欧洲国家的数据,我写道:

country=['Austria', 'Belgium', 'Bulgaria', 'Croatia', 'Republic of Cyprus', 'Czech Republic', 
'Denmark', 'Estonia', 'Finland', 'France', 'Germany', 'Greece', 'Hungary', 'Ireland', 'Italy', 
'Latvia', 'Lithuania', 'Luxembourg', 'Malta', 'Netherlands', 'Poland', 'Portugal', 'Romania', 
'Slovakia', 'Slovenia', 'Spain' , 'Sweden']
filtered_df = Data[Data.COUNTRY.isin(country)]'

但它没有在数据框中显示这些提到的国家的行!有什么想法吗?

我会使用 query,这是一个使用鸢尾花数据集的示例。

iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
x1 = ['setosa', 'versicolor']
iris.query('species in @x1')

那么对你来说就是

Data.query('COUNTRY in @country')