Why am I receiving the error: TypeError: '<=' not supported between instances of 'str' and 'int'?
Why am I receiving the error: TypeError: '<=' not supported between instances of 'str' and 'int'?
当试图在点最集中的区域切割数据时,我使用了以下代码:
filtered_data = data[(data['Word count'] <= 3500) & (data['# Shares;'] <= 8000)]
但收到错误:
TypeError: '<=' not supported between instances of 'str' and 'int'*
您知道可能导致该错误的原因吗?
我已经尝试在该行的开头包含 int()
,但它也没有用。
提前致谢!
data
的返回值为字符串。因此,您试图将字符串与 int 进行比较。您需要将每个 data
包装在一个 int()
中,而不是尝试包装整个东西。 IE。
filtered_data = data[(int(data['Word count']) <= 3500) & (int(data['# Shares;']) <= 8000)]
当试图在点最集中的区域切割数据时,我使用了以下代码:
filtered_data = data[(data['Word count'] <= 3500) & (data['# Shares;'] <= 8000)]
但收到错误:
TypeError: '<=' not supported between instances of 'str' and 'int'*
您知道可能导致该错误的原因吗?
我已经尝试在该行的开头包含 int()
,但它也没有用。
提前致谢!
data
的返回值为字符串。因此,您试图将字符串与 int 进行比较。您需要将每个 data
包装在一个 int()
中,而不是尝试包装整个东西。 IE。
filtered_data = data[(int(data['Word count']) <= 3500) & (int(data['# Shares;']) <= 8000)]