如果句子列中的字符少于 4 个,如何删除数据框行?

How to drop data frame row if there is less than 4 character in sentence column?

假设我已经像这样在我的数据框中标记了句子:

+-----------------------------------------+-----------+
|                sentence                 | sentiment |
+-----------------------------------------+-----------+
| [i, like, this, app, it, s, awesome]    | positive  |
| [way, to, many, ads, pop, up, hate, it] | negative  |
| [ye]                                    | negative  |
| [p]                                     | positive  |
| [niceeeee]                              | positive  |
| [i, do, not, like, the, design]         | negative  |
| [very, useful, recommended]             | positive  |
| [ugly]                                  | negative  |
| [xxx]                                   | negative  |
| [yes]                                   | positive  |
+-----------------------------------------+-----------+

如果句子列少于 4 个字符,我想通过删除 df 行来清除数据框中不需要的数据,所以最终结果将是这样的:

+-----------------------------------------+-----------+
|                sentence                 | sentiment |
+-----------------------------------------+-----------+
| [i, like, this, app, it, s, awesome]    | positive  |
| [way, to, many, ads, pop, up, hate, it] | negative  |
| [niceeeee]                              | positive  |
| [i, do, not, like, the, design]         | negative  |
| [very, useful, recommended]             | positive  |
| [ugly]                                  | negative  |
+-----------------------------------------+-----------+

有谁能提供解决这个问题的程序代码吗?非常感谢您的帮助,这将有助于我的论文工作,感谢您的关注

您可以为此使用 apply 函数

char_limit=4
df[df['sentence'].apply(lambda x : len("".join(x))>=char_limit)]