第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 XML 數(shù)據(jù)創(chuàng)建 pandas 數(shù)據(jù)框

從 XML 數(shù)據(jù)創(chuàng)建 pandas 數(shù)據(jù)框

牛魔王的故事 2022-11-01 16:53:32
我正在處理一個 XML 數(shù)據(jù)文件,其中包含足球比賽期間球員的跟蹤數(shù)據(jù)。查看 XML 數(shù)據(jù)文件頂部的片段:<?xml version="1.0" encoding="utf-8"?><Tracking update="2017-01-23T14:41:26">  <Match id="2019285" dateMatch="2016-09-13T18:45:00" matchNumber="13">    <Competition id="20159" name="UEFA Champions League 2016/2017" />    <Stadium id="85265" name="Estádio do SL Benfica" pitchLength="10500" pitchWidth="6800" />    <Phases>      <Phase start="2016-09-13T18:45:35.245" end="2016-09-13T19:31:49.09" leftTeamID="50157" />      <Phase start="2016-09-13T19:47:39.336" end="2016-09-13T20:37:10.591" leftTeamID="50147" />    </Phases>    <Frames>      <Frame utc="2016-09-13T18:45:35.272" isBallInPlay="0">        <Objs>          <Obj type="7" id="0" x="-46" y="-2562" z="0" sampling="0" />          <Obj type="0" id="105823" x="939" y="113" sampling="0" />          <Obj type="0" id="250086090" x="1194" y="1425" sampling="0" />          <Obj type="0" id="250080473" x="37" y="2875" sampling="0" />          <Obj type="0" id="250054760" x="329" y="833" sampling="0" />          <Obj type="1" id="98593" x="-978" y="654" sampling="0" />          <Obj type="0" id="250075765" x="1724" y="392" sampling="0" />          <Obj type="1" id="53733" x="-4702" y="45" sampling="0" />          <Obj type="0" id="250101112" x="54" y="1436" sampling="0" />          <Obj type="1" id="250017920" x="-46" y="-2562" sampling="0" />          <Obj type="1" id="105588" x="-1449" y="209" sampling="0" />          <Obj type="1" id="250003757" x="-2395" y="-308" sampling="0" />          <Obj type="1" id="101473" x="-690" y="-644" sampling="0" />          <Obj type="0" id="250075775" x="2069" y="-895" sampling="0" />          <Obj type="1" id="103695" x="-1654" y="-2022" sampling="0" />        </Objs>      </Frame>    </Frames>  </Match></Tracking>
查看完整描述

1 回答

?
呼喚遠(yuǎn)方

TA貢獻(xiàn)1856條經(jīng)驗 獲得超11個贊

我使用xml etree模塊來遍歷 xml 并提取相關(guān)數(shù)據(jù)。注釋在下面的代碼中以解釋該過程:看看它,然后玩代碼。希望它適合您的用例


import xml.etree.ElementTree as ET

from collections import defaultdict


d = defaultdict(list)

#since u r reading from a file,

# root should be root = ET.parse('filename.xml').getroot()

#mine is wrapped in a string hence :

 root = ET.fromstring(data)

#required data is in the Frame section

for ent in root.findall('./Match//Frame'):

    #this gets us the timestamp

    Frame = ent.attrib['utc']

    for entry in ent.findall('Objs/Obj'):

        #append the objects to the relevant timestamp

        d[Frame].append(entry.attrib)


df = (pd.concat((pd.DataFrame(value) #create dataframe of the values

                 .assign(Frame=key) #assign keys to the dataframe

                 .filter(['id','Frame','x','y','z']) #keep only required columns

                 for key, value in d.items()),

                axis=1) #concatenate on the columns axis

     )


df.head()


id  Frame   x   y   z   id  Frame   x   y   z

0   0   2016-09-13T18:45:35.272 -46 -2562   0   0   2016-09-13T18:45:35.319 -46 -2558   0

1   105823  2016-09-13T18:45:35.272 939 113 NaN 105823  2016-09-13T18:45:35.319 938 113 NaN

2   250086090   2016-09-13T18:45:35.272 1194    1425    NaN 250086090   2016-09-13T18:45:35.319 1198    1426    NaN

3   250080473   2016-09-13T18:45:35.272 37  2875    NaN 250080473   2016-09-13T18:45:35.319 36  2874    NaN

4   250054760   2016-09-13T18:45:35.272 329 833 NaN 250054760   2016-09-13T18:45:35.319 330 833 NaN



查看完整回答
反對 回復(fù) 2022-11-01
  • 1 回答
  • 0 關(guān)注
  • 109 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號