我正在尝试将 XML 文件中的信息解析为已经使用 Petl 从另一个 CSV 文件创建的表,并且在fromxml()
函数的语法上遇到问题。
XML 文件包含:
<Locations>
<qld_location>
<Suburb>Brisbane-Central</Suburb>
<Lat>-27.46758</Lat>
<Long>153.027892</Long>
</qld_location>
<qld_location>
<Suburb>Robertson</Suburb>
<Lat>-27.565733</Lat>
<Long>153.057213</Long>
</qld_location>
<qld_location>
<Suburb>Logan-Village</Suburb>
<Lat>-27.767054</Lat>
<Long>153.116881</Long>
</qld_location>
</Locations>
我目前有一张桌子:
import petl as etl
table = (
etl
.fromcsv('QLD_Health_Care_Practices.csv')
.convert('Practice_Name', 'upper')
.convert('Suburb', str)
.convert('State', str)
.convert('Postcode', str)
)
+-----------------------------------+--------------------+-------+----------+
| Practice_Name | Suburb | State | Postcode |
+===================================+====================+=======+==========+
| 'BRISBANE CENTRE HEALTH SERVICES' | 'Brisbane-Central' | 'QLD' | '4000' |
+-----------------------------------+--------------------+-------+----------+
| 'ROBERTSON FAMILY PRACTICE' | 'Robertson' | 'QLD' | '4109' |
+-----------------------------------+--------------------+-------+----------+
| 'LOGAN VILLAGE CLINIC' | 'Logan-Village' | 'QLD' | '4207' |
+-----------------------------------+--------------------+-------+----------+
| 'IPSWICH HEALTH CLINIC' | 'Ipswich' | 'QLD' | '4305' |
+-----------------------------------+--------------------+-------+----------+
| 'CATTLE CREEK CLINIC' | 'Cattle Creek' | 'QLD' | '4407' |
+-----------------------------------+--------------------+-------+----------+
并希望在 XML 文件的新列中添加经度和纬度。
我正在尝试使用该功能:
table1= (etl.fromxml('QLD_Locations.xml', 'Locations', 'qld_location', 'Suburb', 'Lat', 'Long')
但是在理解这种 XML 语法所需的参数时遇到了麻烦。
任何帮助将不胜感激,在此先感谢。