Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python中对满足特定条件的行进行子集划分_Python_Pandas - Fatal编程技术网

如何在Python中对满足特定条件的行进行子集划分

如何在Python中对满足特定条件的行进行子集划分,python,pandas,Python,Pandas,我有一个这样的数据帧 Country Year GDP (bil) USA 1970 1073 China 1970 92.6 India 1970 62.42 Spain 1970 40.99 France 1970 148.5 USA 1980 2857 China 1980 191.1 India 1980 186.3 Japan 1980 1105

我有一个这样的数据帧

Country   Year    GDP (bil)
USA       1970    1073
China     1970    92.6
India     1970    62.42
Spain     1970    40.99
France    1970    148.5
USA       1980    2857
China     1980    191.1
India     1980    186.3
Japan     1980    1105
S.Korea   1980    64.98
Singapore 1980    11.9
USA       1990    5963
China     1990    360.9
India     1990    321
Thailand  1990    85.34
Singapore 1990    36.14
我想对这些数据进行细分,得到美国、中国和印度这些年的GDP。还有一个问题,假设我每年有200个国家的GDP数据,而我只对50个国家感兴趣。如何对数据进行子集划分? 多谢各位

您可以使用:

df[df.Country.isin(['USA', 'China', 'India'])][['Country', 'GDP']]
输出: