【问题标题】:Python str.count doesn't return valuesPython str.count 不返回值
【发布时间】:2021-07-30 23:42:34
【问题描述】:

这是我的台词:

df['VN_J'] = df['Vote_Now'].str.count("JD(U)")

但即使数据框中的字符串匹配JD(U),结果也是错误的

谁能帮帮我?

【问题讨论】:

    标签: pandas string count


    【解决方案1】:

    您传递给str.count 的参数实际上被解释为正则表达式。因此,由于() 都是正则表达式元字符,所以这里需要对其进行转义:

    df['VN_J'] = df['Vote_Now'].str.count(r'JD\(U\)')
    

    【讨论】:

      猜你喜欢
      • 2012-10-06
      • 1970-01-01
      • 2017-04-07
      • 2017-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-22
      相关资源
      最近更新 更多