根据pandas列中的多个值从DataFrame中选择行 [英] Select rows from a DataFrame based on multiple values in a column in pandas

查看:247
本文介绍了根据pandas列中的多个值从DataFrame中选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是重复性的问题,但与

This is not a repetitive question, yet similar to

从中选择行一个基于熊猫列中的值的DataFrame

在上一个链接中的答案中,仅基于一个条件,如果我有多个条件,该怎么办.

In that answer up in the previous link it is only based on one criteria what if I have more than one criteria.

我想在一列中选择许多行,而不仅仅是基于特定值的行.为了争论起见,请考虑世界银行的数据框架

I would like to select many rows in a column not only one based on particular values. For the sake of argument consider the DataFrame from the World Bank

import pandas.io.wb as wb
import pandas as pd
import numpy as np
df2= wb.get_indicators()

我选择一个certian值的方式就是这样

The way I select a certian value is as so

df2.loc[df2['id'] == 'SP.POP.TOTL']

df2.loc[df2['id'] == 'NY.GNP.PCAP.CD']

如何在一个新数据框中选择两个,或者说3或4?这样的行是:

How may I select both in one new dataframe or say 3 or 4? such that the rows are:

'SP.POP.TOTL'
'NY.GNP.PCAP.CD'

提前谢谢

推荐答案

您可以使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆