python query isin
时间: 2023-10-31 22:28:18 浏览: 44
The isin() function in Python is used to check if the values in a series or dataframe are present in a list or array. It returns a boolean array indicating whether each element in the series or dataframe is contained in the input list or array.
Syntax:
pd.Series.isin(values)
Example:
import pandas as pd
data = {'Name': ['Alice', 'Bob', 'Charlie', 'David'],
'Age': [25, 30, 35, 40],
'City': ['New York', 'Paris', 'London', 'San Francisco']}
df = pd.DataFrame(data)
# Checking if 'Bob' and 'David' are present in the 'Name' column
result = df['Name'].isin(['Bob', 'David'])
print(result)
Output:
0 False
1 True
2 False
3 True
Name: Name, dtype: bool
Here, the isin() function is used to check if the values "Bob" and "David" are present in the "Name" column of the dataframe. The function returns a boolean array indicating whether each element in the column is contained in the input list.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)