繁体   English   中英

根据列值列表删除多行

[英]Dropping multiples rows based on list of column values

我正在研究世界银行的二氧化碳排放量和 GDP 数据集。 我想从数据框中删除非国家/地区的值。

我尝试使用否定和 reset_index 如下。 但是这些行没有被删除。 我希望删除列“国家/地区名称”中的国家/地区名称来自非国家/地区列表的行。

df_indicator  = df_indicator[~df_indicator['Country Name'].isin(non_countries)]
df_indicator.reset_index(inplace=True, drop=True)

我想从数据框中删除的非国家/地区列表如下:

non_countries=['World','High income','OECD members','Post-demographic dividend','IDA & IBRD total','Low & middle income','Middle income','IBRD only', 'East Asia & Pacific','Europe & Central Asia','North America','Upper middle income','Late-demographic dividend','European Union','East Asia & Pacific (excluding high income)',
 'East Asia & Pacific (IDA & IBRD countries)','Euro area','Early-demographic dividend','Lower middle income','Latin America & Caribbean','Latin America & the Caribbean (IDA & IBRD countries)','Latin America & Caribbean (excluding high income)','Europe & Central Asia (IDA & IBRD countries)','Middle East & North Africa','Europe & Central Asia (excluding high income)','South Asia (IDA & IBRD)','South Asia','Arab World','IDA total','Sub-Saharan Africa','Sub-Saharan Africa (IDA & IBRD countries)','Sub-Saharan Africa (excluding high income)','Middle East & North Africa (excluding high income)','Middle East & North Africa (IDA & IBRD countries)','Central Europe and the Baltics','Pre-demographic dividend','IDA only','Least developed countries: UN classification','IDA blend','Fragile and conflict affected situations','Heavily indebted poor countries (HIPC)','Low income', 'Small states','Other small states','Not classified','Caribbean small states','Pacific island small states']

删除此类行的最有效方法是什么?

尝试这个:

df_indicator = df_indicator.loc[~df_indicator['Country Name'].isin(non_countries)]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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