Pandas extract numbers from column into new columns

后端 未结 5 2328
谎友^
谎友^ 2020-12-21 05:51

I currently have this df where the rect column is all strings. I need to extract the x, y, w and h from it into separate columns. The dataset is very large so I need an effi

5条回答
  •  自闭症患者
    2020-12-21 06:15

    This is one of those cases where it makes sense to "optimize" the data itself instead of trying to morph it into what a consumer wants. It's much easier to change clean data into a specialized format than it is to change a specialized format into something portable.

    That said, if you really have to parse this, you can do something like

    >>> import re
    >>> re.findall(r'\d+', '')
    ['120', '168', '260', '120']
    >>>
    

提交回复
热议问题