删除基于len(columns)的数据框上的行

我有3个数据框,其中包含english_words,名称和位置。对于每个数据框,我试图删除所有长度小于3的单词,并且我使用以下代码:

english_words=english_words[english_words[0].map(len) >= 3]
names=names[names[0].map(len) >= 3]
places=places[places[0].map(len) >=3]

所有数据框只有一列。 我期望获得仅具有长度大于或等于3的单词的新数据帧,但我收到以下错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-21-d16d0eaf3a11> in <module>
----> 1 english_words=english_words[[(len(x) > 5) for x in english_words[0]]]
      2 names=names[names[0].map(len) >= 3]
      3 places=places[places[0].map(len) >=3]

<ipython-input-21-d16d0eaf3a11> in <listcomp>(.0)
----> 1 english_words=english_words[[(len(x) > 5) for x in english_words[0]]]
      2 names=names[names[0].map(len) >= 3]
      3 places=places[places[0].map(len) >=3]

TypeError: object of type 'float' has no len()
heiseseo 回答:删除基于len(columns)的数据框上的行

问题已解决,这是更新的代码:

english_words=english_words[[(len(str(x)) >=3) for x in english_words[0]]]
names=names[[(len(str(x)) >=3) for x in names[0]]]
places=places[[(len(str(x)) >=3) for x in places[0]]]
本文链接:https://www.f2er.com/3140457.html

大家都在问