-
Notifications
You must be signed in to change notification settings - Fork 0
/
featherdata.py
70 lines (53 loc) · 1.53 KB
/
featherdata.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
#coding:utf-8
import pandas as pd
import feather as ft
def dfvars(ncol):
dfvars=''
for var in range(1,ncol+1):
dfvars+='x%d,' %var
dfvars=dfvars[:len(dfvars)-1]
return dfvars
vars=dfvars(261)
selcols=[1,5,31,33,34,35,59,
64,69,70,71,72] + range(229,259)
def selvars(selcols):
selvars=''
for col in selcols:
selvars+='x%d,'%col
selvars=selvars[:-1]
return(selvars)
selvars=selvars(selcols)
reader = pd.read_csv(
'/mnt/f/data/2013/1301.csv',
iterator=True)
reader._currow = 0
loop = True
chunkSize = 50000
hoscodes = []
looptimes=0
path = '/mnt/e/ipy/procdata/2013/rec13.pyr'
while loop:
try:
looptimes+=1
df =reader.get_chunk(chunkSize)
df.columns=vars.split(',')
df_rep=df.ix[:,selvars.split(',')]
df_rep=df_rep.astype('str')
ft.write_dataframe(df_rep,path+
str(looptimes))
except StopIteration:
loop =False
print"Iteration is stopped."
'''
files = os.listdir('e:/ipy/procdata/2013')
hos = pd.DataFrame()
for file in files:
hos_rep = pd.read_csv('e:/ipy/procdata/2013/'
+file,header=None,
encoding='utf-8')
hos = pd.concat([hos,hos_rep],axis=0)
hos.to_csv('e:/ipy/procdata/2013/'+
'csv2013'+'.csv',
index=None,encoding='utf-8')
'''