【发布时间】:2013-03-05 23:21:27
【问题描述】:
我在 csv 文件中有大量 GPS 数据集。
是这样的。
12,1999-09-08 12:12:12, 116.3426, 32.5678
12,1999-09-08 12:12:17, 116.34234, 32.5678
.
.
.
每列的格式为id, timestamp, longitude, latitude
现在,我正在使用 pandas 并将文件导入数据框,到目前为止我已经编写了这段代码。
import pandas as pd
import numpy as np
#this imports the columns and making the timestamp values as row indexes
df = pd.read_csv('/home/abc/Downloads/..../366.txt',delimiter=',',
index_col=1,names=['id','longitude','latitude'])
#removes repeated entries due to gps errors.
df = df.groupby(df.index).first()
有时,同一日期会有 2 或 3 个多个条目,应该删除
我得到了这样的东西
id longitude latitude
1999-09-08 12:12:12 12 116.3426 32.5678
1999-09-08 12:12:17 12 116.34234 32.5678
# and so on with redundant entries removed
现在我希望对具有相同纬度和经度的行进行连续索引.. 即,我的可视化是
id longitude latitude
0 1999-09-08 12:12:12 12 116.3426 32.5678
1 1999-09-08 12:12:17 12 116.34234 32.5678
2 1999-09-08 12:12:22 12 116.342341 32.5678
1999-09-08 12:12:27 12 116.342341 32.5678
1999-09-08 12:12:32 12 116.342341 32.5678
....
1999-09-08 12:19:37 12 116.342341 32.5678
3 1999-09-08 12:19:42 12 116.34234 32.56123
and so on..
即,具有相同纬度和经度值的行将被连续索引。我怎样才能做到这一点?我是熊猫的初学者,所以我不太了解它。请帮忙!
【问题讨论】:
标签: python-2.7 pandas