Pandas-计算字符字段中逗号的数量 [英] Pandas - Counting quantity of commas in character field

查看:284
本文介绍了Pandas-计算字符字段中逗号的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个熊猫数据框,其中的一列填充有字符串,如下所示:

I have a pandas dataframe with a column filled with strings as is shown below:

   string_column
0  t,d,t,d,v,d
1  s,v,y,d
2  d,u,f

我想用字符串列中的逗号计数创建一个新列.我的预期结果如下:

I would like to create a new column with the count of commas in the string column. My intended outcome is below:

   string_column  comma_count
0  t,d,t,d,v,d    5
1  s,v,y,d        3
2  d,u,f          2

大熊猫是否有可以完成此任务的字符串读取方法?

Is there a string reading method to pandas that will accomplish this task?

谢谢

推荐答案

使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆