nexsted子级和子级的python xml解析并存储到datafram中

2024-06-16 12:40:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我想通过一个xml进行解析并加载到python中的数据帧中。我希望将子值存储到数据帧中,并将子子值也存储到数据帧中

例如:

-<EstablishmentCollection>


-<EstablishmentDetail>

<FHRSID>1156922</FHRSID>

<LocalAuthorityBusinessID>PI/000130527</LocalAuthorityBusinessID>

<BusinessName>1 Haldynby Gardens</BusinessName>

<BusinessType>Other catering premises</BusinessType>

<BusinessTypeID>7841</BusinessTypeID>

<RatingValue>5</RatingValue>

<RatingKey>fhrs_5_en-GB</RatingKey>

<RatingDate>2019-06-18</RatingDate>

<LocalAuthorityCode>408</LocalAuthorityCode>

<LocalAuthorityName>Doncaster</LocalAuthorityName>

<LocalAuthorityWebSite>http://www.doncaster.gov.uk</LocalAuthorityWebSite>

<LocalAuthorityEmailAddress>food.safety@doncaster.gov.uk</LocalAuthorityEmailAddress>


-<Scores>

<Hygiene>0</Hygiene>

<Structural>0</Structural>

<ConfidenceInManagement>0</ConfidenceInManagement>

</Scores>

<SchemeType>FHRS</SchemeType>

<NewRatingPending>False</NewRatingPending>

<Geocode/>

</EstablishmentDetail>


-<EstablishmentDetail>

<FHRSID>368376</FHRSID>

<LocalAuthorityBusinessID>PI/000094435</LocalAuthorityBusinessID>

<BusinessName>1 High Fisher Gate</BusinessName>

<BusinessType>Hotel/bed & breakfast/guest house</BusinessType>

<BusinessTypeID>7842</BusinessTypeID>

<AddressLine1>Doncaster</AddressLine1>

<PostCode>DN1 1QZ</PostCode>

<RatingValue>5</RatingValue>

<RatingKey>fhrs_5_en-GB</RatingKey>

<RatingDate>2019-06-13</RatingDate>

<LocalAuthorityCode>408</LocalAuthorityCode>

<LocalAuthorityName>Doncaster</LocalAuthorityName>

<LocalAuthorityWebSite>http://www.doncaster.gov.uk</LocalAuthorityWebSite>

<LocalAuthorityEmailAddress>food.safety@doncaster.gov.uk</LocalAuthorityEmailAddress>


-<Scores>

<Hygiene>5</Hygiene>

<Structural>5</Structural>

<ConfidenceInManagement>5</ConfidenceInManagement>

</Scores>

<SchemeType>FHRS</SchemeType>

<NewRatingPending>False</NewRatingPending>


-<Geocode>

<Longitude>-1.13342797756195</Longitude>

<Latitude>53.52546310424800</Latitude>

</Geocode>

</EstablishmentDetail>

DataFrame应该如下所示

FHRSID  LocalAuthorityBusinessID    BusinessName    BusinessType    BusinessTypeID  RatingValue RatingKey   Hygiene Structural  ConfidenceInManagemen

请注意,最后3个属性来自标签


Tags: structuralratingdatebusinessnamebusinesstypeestablishmentdetailhygieneratingvaluebusinesstypeid