Skip to main content
 首页 » 编程设计

python之Pandas 数据框 : how to sentence into words and select rows that have more than 10 words

2025年05月04日22luoye11

我有一个 DataFrame,每行一个句子。但是句子的长度不一样。我想选择那些包含超过 10 个单词的行,比如

df = df.loc[len(df[src].str.split()) > 10] 

但这会引发 Key 为 True 的错误。如何做到这一点?

请您参考如下方法:

试试series.str.len() :

df[df['src'].str.split().str.len() > 10]