【发布时间】:2018-08-27 07:37:57
【问题描述】:
我从 csv 文件导入了以下数据框:
ts employee_id gps_lat gps_lng event_id event_params speed status serial_number
9/22/2016 13:53 1 34.97 -81.98 Down {"type":"Down","maximumangle":0,"duration":0} 0 1100110 211
9/22/2016 13:53 1 34.97 -81.98 Left {"type":"Left","maximumangle":-38.57,"duration":203} 0 1102110 212
9/22/2016 13:53 1 34.97 -81.98 Right {"type":"Right","maximumangle":52.975,"duration":17} 0 1102130 250
9/22/2016 13:53 1 34.97 -81.98 Down {"type":"Down","maximumangle":0,"duration":0} 0 1102130 249
9/22/2016 13:54 1 34.97 -81.98 Down {"type":"Down","maximumangle":0,"duration":0} 0 1102140 280
9/22/2016 13:54 1 34.97 -81.98 Left {"type":"Left","maximumangle":-10.866,"duration":40} 0 1102140 279
我需要将 event_params 列拆分为带有标题的单独列 - 类型、最大角度和持续时间,并且我需要去掉花括号。总之我需要以下输出。
ts employee_id gps_lat gps_lng event_id Type maximumangle duration speed status serial_number
9/22/2016 13:53 1 34.97 -81.98 Down Down 0 0 0 1100110 211
9/22/2016 13:53 1 34.97 -81.98 Left Left -38.57 203 0 1102110 212
9/22/2016 13:53 1 34.97 -81.98 Right Right 52.975 17 0 1102130 250
9/22/2016 13:53 1 34.97 -81.98 Down Down 0 0 0 1102130 249
9/22/2016 13:54 1 34.97 -81.98 Down Down 0 0 0 1102140 280
#Code I am trying to use:
import re
parts = re.split('\df3|(?<!\d)[:.](?!\d)', df3)
parts
我试图通过首先拆分它来解决这个问题:分隔符,然后用 } 拆分最后一列,然后删除内容最大角度和持续时间的列。
我一直在尝试通过以下方式使用 re.split 函数,但它返回错误
--expected string or bytes-like object
【问题讨论】:
标签: python regex pandas delimiter