提取csv文件的多个面坐标

时间:2019-02-26 22:10:11

标签: python pandas csv dataframe polygon

我想将.xlsx文件的(多个)多边形坐标提取到Python中的Panda Dataframe中。

.xlsx文件位于google docs上。

现在我这样做:

import pandas as pd  

gemeenten2019 = pd.read_excel('document.xlsx', index=False, skiprows=0 )
gemeenten2019['KML'] = str(gemeenten2019['KML'])

for index, row in gemeenten2019.iterrows():
    removepart = str(row['KML'])
    row['KML'] = removepart.replace('<MultiGeometry><Polygon><coordinates>', '')

gemeentenamen = []
gemeentePolygon = []

for gemeentenaam in gemeenten2019['NAAM']:
    gemeentenamen.append(str(gemeentenaam))

for value in gemeenten2019['KML']:
    gemeentePolygon.append(str(value))


df_gemeenteCoordinaten = pd.DataFrame({'Gemeente':gemeentenamen, 'KML': gemeentePolygon})
df_gemeenteCoordinaten

但是结果是每个列(“ KML”)都有相同的结果。

result

仅我想要该特定行的坐标作为他的列,而不是所有列的所有坐标。

数据框必须如下所示:

this

有人知道如何为每一行提取多个坐标吗?

1 个答案:

答案 0 :(得分:0)

这将给您每对值各自的一行:

import pandas as pd  

gemeenten2019 = pd.read_excel('Gemeenten 2019.xlsx', index=False, skiprows=0)
gemeenten2019['KML'] = gemeenten2019['KML'].str.strip('<>/abcdefghijklmnopqrstuvwxyzGMP').str.replace(' ', '\n')

例如:

                    NAAM                                                KML
0            Aa en Hunze  6.81394482119469,53.070971596018\n6.8612875225...
1               Aalsmeer  4.79469736599488,52.2606817589009\n4.795085405...
2                 Aalten  6.63891586106867,51.9625470164657\n6.639463741...
3          Achtkarspelen  6.23217311778447,53.2567474241222\n6.235100748...