【问题标题】:how we can use split function with multiple _我们如何使用带有多个 _ 的 split 函数
【发布时间】:2021-02-11 22:16:22
【问题描述】:
data = ['test_function']

如果我们想拆分'test_function',我们使用以下命令(学习内容)

test = data['test_function'].str.split('_', expand = True)

然后它将创建两行'test'和'function'

如果

data = ['test_function_practice']

我们只想将“测试”和“功能”分开,我们如何做到这一点

【问题讨论】:

    标签: python pandas string split


    【解决方案1】:

    您可以通过n 更改拆分次数的限制。

    尝试:

    test = data['test_function'].str.split('_', n = 1, expand = True)
    

    输出:

          0                  1
    0  test  function_practice
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-17
      • 2016-09-05
      • 1970-01-01
      相关资源
      最近更新 更多