【发布时间】:2021-05-01 12:24:21
【问题描述】:
我想通过使用同一行中第二列的值将一列拆分为两列,因此第二列值用作拆分分隔符。
我收到了错误 TypeError: 'Series' objects are mutable, thus they cannot be hashed,这是有道理的,它接收的是一个系列,而不是单个值,但我不确定如何隔离到第二列的单行值。
样本数据:
title_location delimiter
0 Doctor - ABC - Los Angeles, CA - ABC -
1 Lawyer - ABC - Atlanta, GA - ABC -
2 Athlete - XYZ - Jacksonville, FL - XYZ -
代码:
bigdata[['title', 'location']] = bigdata['title_location'].str.split(bigdata['delimiter'], expand=True)
期望的输出:
title_location delimiter title location
0 Doctor - ABC - Los Angeles, CA - ABC - Doctor Los Angeles, CA
1 Lawyer - ABC - Atlanta, GA - ABC - Lawyer Atlanta, GA
2 Athlete - XYZ - Jacksonville, FL - XYZ - Athlete Jacksonville, FL
【问题讨论】:
标签: python pandas string split delimiter