如何使用pandas将非结构化数据转换为结构化数据

问题描述 投票:0回答:1

我有一堆巨大的传感器数据,位于 Excel 文件中,数据看起来像 json 格式(不完全是),需要解析数据我不知道数据看起来像这样

FM4 [Priority=0] [GPS element=[X=776517049] [Y=128887449] [Speed=4] [Angle=102] [Altitude=900] [Satellites=8]] [IO=[239=1] [240=1] [80=1] [21=5] [200=0] [69=1] [1=1] [179=0] [2=1] [180=0] [113=99] [841=0] [842=0] [181=14] [182=10] [66=12087] [24=4] [205=28441] [206=31908] [67=4117] [68=0] [9=12157] [17=-152] [18=0] [19=123] [6=-21015] [241=40486] [800=12087] [840=44496] [14=4619303992] [11=899186004] ] [Timestamp=1666676090000] [EventSource=0] [IMEI = 357544375160179]:::5548###[[IMEI = 357544375160179],[Latitude = 128887449],[Longitude = 776517049],[Speed = 4],[Angle = 102],[Altitude = 900],[Odometer = 0],[IO = [Power = 0] [Digital Input 1 = 1] [Digital Input 2 = 1] [Battery Current = 0] [Analog Input 2 = 44521] [Sleep Mode = 0] [Analog Input 1 = 12157] [ICCID = 899186004] [ICCID2 = 4619303992] [Axis X = -152] [Asis Y = 0] [Asis Z = 123] [Data Mode = 1] [PDOP = 14] [Speed = 4] [External Voltage = 12087] [Battery Voltage = 4117] [GSM Signal = 5] [GPS Validity = 1] [Battery Percentage = 99] [Ignition = 1] [Movement = 1] [Active GSM Operator = 40486] [Digital Output 1 = 0] [Digital Output 2 = 0] [Voltage = 12087] ]]######Device Time : 2022-10-25 05:34:50, Time Zone Of Device Set On System : Plus 00:00###
这只是一行数据 预期输出是 https://docs.google.com/spreadsheets/d/1p4CgX1ZLQVgAOOAw8cBUtQ5p3RwFfci4hcsf7oPB-qE/edit?usp=sharing这是我的数据,前12列格式正确,13列数据被合并,无法解析数据如何在Python中做到这一点。

如何使用 python 来做到这一点

json pandas numpy data-science
1个回答
0
投票

首先下载文件并通过 Excel 将其另存为 .csv(逗号分隔值)。 然后通过写入导入 pandas 库:

import pandas as pd

然后读取该文件并将其转换为 DataFrame,如下所示:

data=pd.read_csv('yourfilename.csv')

现在您有了可以轻松分析的表格数据!

© www.soinside.com 2019 - 2024. All rights reserved.