CSV 到 XML 交替值

问题描述

我正在尝试将 CSV 转换为 XML,以便我可以在 Garmin 设备上显示路线。但是,我的坐标在列表中的顺序错误,无法在我将在其上显示点的地图上创建路线。 csv 是通过程序生成的,所以我不能简单地编辑表格。这是我当前的工作代码

import pandas as pd
df = pd.read_csv(os.getcwd()+'\\file1.csv',sep=',')
def convert_row(row):
    return """          <waypoint>
            <identifier>%s_1</identifier>
            <type></type>
            <lat>%s</lat>
            <lon>%s</lon>
        </waypoint>
        <waypoint>
            <identifier>%s_2</identifier>
            <type></type>
            <lat>%s</lat>
            <lon>%s</lon>
        </waypoint>""" % (
    row.run,row.lon_1,row.lat_1,row.run,row.lon_2,row.lat_2)
with open(os.getcwd()+'\\file.csv',"w+") as f2:
        f2.write('\n'.join(df.apply(convert_row,axis=1)))

为了多解释一点,我有每条线的起点坐标和终点坐标。我想要点排序,以便可以像这样绘制路径:start1,end1,end2,start 2,start3,end3,end4,start4.....

有谁知道如何实现这一目标?提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)