'>' 'str'和'int'实例之间不受支持 [英] '>' not supported between instances of 'str' and 'int'

查看:78
本文介绍了'>' 'str'和'int'实例之间不受支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了错误

在'str'和'int'的实例之间不支持

'>'

'>' not supported between instances of 'str' and 'int'

尝试在Pandas数据框中打印以下行

while trying to print the below lines in Pandas dataframe

print (survey_df_clean.shape)
print (survey_df_clean[survey_df_clean['text']>30].shape)

我应该尝试将它们转换为int,并且在此语句中如何工作?

Should I try to convert them to int and how would that work in this statement?

推荐答案

此消息建议您尝试将字符串对象(str)与整数(int)进行比较. 表达式

This message suggests, that you try to compare a string object (str) with an integer (int). The expression

survey_df_clean['text']

可能会返回一个字符串.因此,您不能直接将其与数字30进行比较.如果要比较条目的长度,可以使用pandas.Series.str.len()操作,因为您会看到

will probably return a string. Therefore, you cannot directly compare it with the number 30. If you want to compare the length of the entry, you can use the pandas.Series.str.len() operation as you can see here.

如果此字段实际包含一个整数,则可以使用方法( pandas.to_numeric)将其从str投射到int.

If this field should actuallty contain an integer, you can use this method (pandas.to_numeric) to cast it from str to int.

这篇关于'>' 'str'和'int'实例之间不受支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆