df 分割列

https://zhuanlan.zhihu.com/p/343895339

  1. >>> df['AB_split'] = df['AB'].str.split('-')
  2. >>> df
  3. AB AB_split
  4. 0 A1-B1 [A1, B1]
  5. 1 A2-B2 [A2, B2]
  6. >>> df['A'], df['B'] = df['AB'].str.split('-', 1).str
  7. >>> df
  8. AB AB_split A B
  9. 0 A1-B1 [A1, B1] A1 B1
  10. 1 A2-B2 [A2, B2] A2 B2