首页 > 解决方案 > 如何从 Pandas 数据框中获取选定的选择行?

问题描述

我有一个包含国家列表和其他信息的数据框(名为能源) 。图像如下所示。

我只想选择特定国家及其相关信息。我需要的国家由另一个名为SCI_Mago的数据框选择。

我怎么能在熊猫中做到这一点?我将编写我想要的伪代码。我无法帮助自己使用确切的代码,无论我尝试什么都给了我错误。

伪代码

#First I create the list from a dataframe named SCI_Mago. I want these countries for my next data frame
country_list =SCI_Mago['Country'].tolist()

#I use this list to get only relevant countries from another dataframe named 'energy'
new_DF = energy[energy['Country'] ==  country_list]

...

名为“能量”的数据框的图像

标签: pythonpandasdataframe

解决方案


推荐阅读