首页 > 解决方案 > Python pandas 解析记录

问题描述

我需要解析数据框中的数据,消除括号内的所有内容,然后将所述数据移动到新列。理想情况下,如果可以在新列中消除括号,那也很好,但我认为这两种结果都会产生预期的解决方案:

current column                                  new column
/reports/industry(5315)/2018                    (5315)
/reports/limit/sector(139)/2017                 (139)
/reports/sector/region(147,189 and 132)/2018    (147,189 and 132)

谢谢你,你能给的任何方向都会很棒!

标签: pythonregexpandas

解决方案


IIUC 提取物

df.current.str.extract('.*\((.*)\).*',expand=True)
Out[785]: 
               0
0           5315
1            139
2147,189 and 132

推荐阅读