【发布时间】:2021-04-17 01:08:48
【问题描述】:
这是我的专栏:
ReviewText
Absolutely wonderful silky and..
Love this dress! it is so pretty...
I had such high hopes for...
我想创建一个名为 Avg_length 的新列,其中包含 ReviewText 列中单词的平均长度...
我编写了以下代码来在每个空格之后拆分字符串:
df['Avg_length'] = df["Review Text"].apply(lambda x: len(x.split()))
现在如何计算平均值?
提前谢谢...
【问题讨论】:
-
df["Review Text"].mean()? -
df['ReviewText'].str.split().map(len).mean()
标签: python pandas numpy python-requests jupyter-notebook