【发布时间】:2021-02-15 13:13:55
【问题描述】:
我有一个 df 列,我想只过滤负值或正值,
当我尝试以下代码时:
df.loc[df['values'] > 0]
我得到错误
`TypeError: '>' not supported between instances of 'str' and 'int'
我尝试将值列的对象数据类型转换为整数:
df['values'].astype(str).astype(int)
我收到以下错误:ValueError: invalid literal for int() with base 10: '3.69'
谢谢!
如何正确转换以便正确过滤?谢谢!
【问题讨论】:
-
将其转换为浮点数(3.69 为浮点数)
标签: python python-3.x pandas data-science