我在employeedata.xml 文件中有员工数据。我的样本数据如下所示
<?xml version="1.0" standalone="yes"?>
<DocumentElement>
<_x005B_dbo_x005D_._x005B_employeedata_x005D_>
<RowID>11148</RowID>
<ItemID>966109</ItemID>
<Mappings>[]</Mappings>
<Groups>93664,68349</Groups>
<GroupKey>7003142</GroupKey>
<ParentItemID>351908</ParentItemID>
<JobID>30318</JobID>
<Action>Employee</Action>
<Employee_Name>John Travis</Employee_Name>
<mail_id>[email protected]</mail_id>
<...>...</...>
<Action>Experience</Action>
<...>...</...>
<...>...</...>
<...>...</...>
我使用 python 3.8.10 来读取文件。我正在使用以下代码来读取我的数据
with open('employeedata.xml', 'r') as f:
data = f.read()
我想将我的xml存储在pandas数据框中,其中标签
Action
下的值将存储在Action
列中,相应的标签将存储在其他列Field
中。我的示例输出看起来像
| Action | Field |
|--------------|-------------|
| Employee |Employee_Name|
| Employee |mail_id |
| Employee |.... |
| Employee |.... |
| Experience|.... |
| Experience|.... |
您能建议我该怎么做吗?
您可能正在寻找这个 python xml 解析器模块
您的情况:
import xml.etree.ElementTree as ET
tree = ET.parse('employeedata.xml')
root = tree.getroot()