【发布时间】:2021-12-24 15:32:23
【问题描述】:
我想检查 pandas.DataFrame 列是否包含特定值。例如,这个玩具数据框在"two" 列中有一个"h":
import pandas as pd
df = pd.DataFrame(
np.array(list("abcdefghi")).reshape((3, 3)),
columns=["one", "two", "three"]
)
df
one two three
0 a b c
1 d e f
2 g h i
但令人惊讶的是,
"h" in df["two"]
计算为False。
我的问题是:找出 DataFrame 列(或一般pandas.Series)是否包含特定值的最清晰方法是什么?
【问题讨论】:
标签: pandas