python - 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)
谢谢你,你能给的任何方向都会很棒!
解决方案
IIUC 提取物
df.current.str.extract('.*\((.*)\).*',expand=True)
Out[785]:
0
0 5315
1 139
2147,189 and 132
推荐阅读
- python - 如何在一个函数中替换数据后连接两个熊猫数据框
- javascript - Array.prototype.fill 在 Array.prototype.map 中的异常行为
- sockets - 使用未绑定或绑定但不监听的套接字
- scala - 将数据从 Amazon redshift 加载到 HDFS
- arrays - 要在 nodeJs 的新行中显示的数组值
- php - 多个相同实体关系
- python - write_csv_rows() 在具有长字符串的大型数据集上非常慢
- c# - ASP.NET Core 2.1 代码生成错误 - 找到多个相同类型的自定义属性
- entity-framework-core - EF 核心,创建自定义默认约束名称
- twitter - Twitter API 返回推文链接,而推文没有链接