Pandas 如何使用len函数来过滤某列 不再提示: 'Series' object has no attribute 'len' 等报错

工作中使用pandas遇到这个情况, 'Series' object has no attribute 'len' 及TypeError: object of type 'float' has no len() , difflib

先暂时记录下当时的处理方法,仅贴出关键代码:

# 数据处理 - 短句过滤: 即至少4个字的评论才会被保留
df["content"] = df["content"].astype(str)
df = df[df["content"].str.len() <= 4]
print(df)

猜你喜欢

转载自blog.csdn.net/qq0719/article/details/85628134