如何确定 Pandas Series 中是否存在非字符串值

MRR*_*MRR 6 python pandas

我正在尝试在 Pandas 系列上使用布尔索引,以确定我的系列中是否有非字符串的值。

到目前为止我的方法是:

contains_non_string = s[type(s) != str].any()
Run Code Online (Sandbox Code Playgroud)

当我运行这个时,我收到以下错误:

TypeError: 'int' object is not subscriptable
Run Code Online (Sandbox Code Playgroud)

如何正确确定我的系列中是否存在非字符串值?我正在运行 Python 3.6 和 Pandas 0.19.2。

acu*_*ner 4

你可以这样做:

contains_non_string = s[s.apply(type) != str].any()
Run Code Online (Sandbox Code Playgroud)