diary20180625

15:00:00 去遥远的湘雅附近买了弹性绷带。

21:08:23 帮政写了个python的程序,现学python的感觉真爽

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

import csv,geohash

l = list()

file2 = open("target.csv","w",newline='')
writer = csv.writer(file2)


file1 = open("train.csv","rt")
reader=csv.reader(file1)
next(reader)
writer.writerow(['orderid','userid','bikeid','biketype','startdate','starttime','geohashed_start_loc_long','geohashed_start_loc_lat','geohashed_end_loc_long','geohashed_end_loc_lat'])
for line in reader:
for index,data in enumerate(line):
if(index<=3):
l.append(data)
if(index==4):
l.append(data.split()[0])
l.append(data.split()[1])
if(index==5):
l.append(geohash.decode(data)[0])
l.append(geohash.decode(data)[1])
if(index==6):
l.append(geohash.decode(data)[0])
l.append(geohash.decode(data)[1])
writer.writerow(l)
l=[]

file1.close()
file2.close()

数据内容样式:

orderid userid bikeid biketype starttime geohashed_start_loc geohashed_end_loc
1893973 451147 210617 2 2017/5/14 22:16 wx4snhx wx4snhj
4657992 1061133 465394 1 2017/5/14 22:16 wx4dr59 wx4dquz
2965085 549189 310572 1 2017/5/14 22:16 wx4fgur wx4fu5n
4548579 489720 456688 1 2017/5/14 22:16 wx4d5r5 wx4d5r4
3936364 467449 403224 1 2017/5/14 22:16 wx4g27p wx4g266
5163705 917620 509044 1 2017/5/14 22:16 wx4gd2e wx4g6pw

转化结果样式:

orderid userid bikeid biketype startdate starttime geohashed_start_loc_long geohashed_start_loc_lat geohashed_end_loc_long geohashed_end_loc_lat
1893973 451147 210617 2 2017/5/14 22:16 40.1 116.29 40.1 116.29
4657992 1061133 465394 1 2017/5/14 22:16 39.79 116.33 39.8 116.32
2965085 549189 310572 1 2017/5/14 22:16 39.88 116.54 39.88 116.55
4548579 489720 456688 1 2017/5/14 22:16 39.77 116.16 39.77 116.16
3936364 467449 403224 1 2017/5/14 22:16 39.96 116.39 39.96 116.38
5163705 917620 509044 1 2017/5/14 22:16 39.99 116.47 39.99 116.46