小编王亦舟*_*王亦舟的帖子

如何在 Pandas 数据框中获取列表的长度

我在熊猫中有一个像这样的数据框:

                                                             List
2013-12-22 15:25:02  [good morning, good afternoon, good evening]
2009-12-14 14:29:32             [happy new year, happy birthday,]
2013-12-22 15:42:00                      [happy, sad, mad, chill]
Run Code Online (Sandbox Code Playgroud)

我怎么得到这样的东西

                                                             List Len
2013-12-22 15:25:02  [good morning, good afternoon, good evening]   3
2009-12-14 14:29:32             [happy new year, happy birthday,]   2
2013-12-22 15:42:00                      [happy, sad, mad, chill]   4
Run Code Online (Sandbox Code Playgroud)

我试过 df['List'].str.len(),但它返回这个列表中有多少单词的长度。

python dataframe pandas

5
推荐指数
1
解决办法
998
查看次数

标签 统计

dataframe ×1

pandas ×1

python ×1