我正在尝试在 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。
你可以这样做:
contains_non_string = s[s.apply(type) != str].any()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2671 次 |
| 最近记录: |