csv - Fiddle out columns in python to save in variables -


i trying 2 colums variable had previous code,

lets example variable got (it nordic format , seismic saff) variable called data.

stat    sp  iphasw  d   hrmm    secon   coda    amplit  peri    azimu   velo    ain ar  tres    w   dis caz7   pb11    bz  ip      d   6 9     31.76   62                                              -0.4810     350 221    pb11    sz  iaml        610     18.65           486.2   1.70                                        350 221    pb08    bz  ip      c   6 9     39.09   62      6.2310                                              353 210    pb08    sz  iaml        610     30.80            232.5  1.80                                        353 210    psgcx   bz  ip      d   6 9     31.60   62      -3.9110                                             372 228    psgcx   sz  iaml        610     55.47           317.5   2.50                                        372 228    pb01    bz  ip      d   6 9     46.54   62      -1.70           9                                   457 207    pb01    sz  iaml        611     7.26            160.1   3.10                                        457 207    mocb    sz  ip      c   6 9     48.34   62      -2.06           9                                   470 156    pb09    bz  ip      c   610     9.79    62      11.72           9                                   523 200    pb09    sz  iaml        611     51.60           478.4   3.00 

the target variable hrmm secon (hour minite senond), 19 29 position.

i wanted separate hours in variable called h, minutes in variable called m , seconsds in avariable called s,

h=[6,6,6,6,6,6,6,...] min=[9, 10, 9, 10, 10, 11,....] seconds=[31.66,18.55,....]

i tryed code,

oo=[] line in data:     parte=line.split('\n')     limp=parte[0]     print limp     linne in limp:         linne=limp.strip()         oo.append(linne[19:29].split('\n'))     print oo  

but unfortanatelly not able this. got this.

00=[6 9 31.33, 6 9 31.33, 6 9 31.33, 6 9 31.33, ......] 

many times same, same number , no separate showed you.

i tryied modifie code this.

for line in data:     parte=line.split('\n')     if len(parte) > 1:         #print parte[0]         lline in parte:             partes=lline.strip('')             partes=lline.split('/t')             print partes 

and got it:

[' stat sp iphasw d hrmm secon coda amplit peri azimu velo ain ar tres w dis caz7']

['']

[' pb11 bz ip d 6 9 31.76 62
-0.4810 350 221 ']

['']

[' pb11 sz iaml 610 18.65 486.2 1.70
350 221 ']

['']

[' pb08 bz ip c 6 9 39.09 62
6.2310 353 210 ']

['']

can give hand?, thank lot time

tonino

dear all, found solution , i'd know if pythonic way it, please feel free comment

indexstat=0 hms=[] in range(len(data)):     if data[i].find("stat ")>=0:         indexstat=i         break     j in range(indexstat+1,len(data)):         ll=data[j]         res=(ll[18:29])         print res 

these lines let me data hrmm secon, had no change count places them, 1 have better idea, works, sure there pythonic way it.

thank lot.

tonino


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -