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

后端 未结 5 1637
忘掉有多难
忘掉有多难 2021-01-13 16:02

I encountered the error

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

while trying to print the below lines in P

5条回答
  •  无人共我
    2021-01-13 16:20

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

    survey_df_clean['text']
    

    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.

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

提交回复
热议问题