数据的最后两列表示[X,Y]坐标对。我想把这些数据组织成一个python中成对列表的列表,这样它看起来像:
coords = [[1486,732],[716,1357],...,[X_ii, Y_ii]]
到目前为止,我已经尝试过:
nodelist = pd.read_csv('https://gist.githubusercontent.com/brooksandrew/f989e10af17fb4c85b11409fea47895b/raw/a3a8da0fa5b094f1ca9d82e1642b384889ae16e8/nodelist_sleeping_giant.csv')
coord_array = pd.DataFrame(nodelist.iloc[:,1:].iterrows())
coords = [[tuple(x)] for x in coord_array.values][0]
但这会产生:
[[[(0, X 1486
Y 732
Name: 0, dtype: int64)], [(1, X 716
Y 1357
Name: 1, dtype: int64)], [(2, X 3164
Y 1111
...
为了在遍历行时保留数据类型,最好使用
itertuples()
,它返回值的namedtuples
,通常比iterrows()
快。Read more here[[e.X, e.Y] for e in nodelist.itertuples()]
相关问题 更多 >
编程相关推荐