1

i have a huge text file It is the second txt file labeled hhrr1996221.txt.zip

I am trying to analyze the data by counts vs time, the times start at 2 ms and then 6 data sets (Counts) are given and repeat.

I have not used python since last year, although i do want to improve my coding skills. I used the following code:

           import numpy as np
           hh=np.loadtxt('hhrr1996221.txt', delimiter=',')
           time= hh[1:,0]

i just wanted to test out if i get an array i eventually want to get the counts in as well and then plot a graph

the error message i get is

runfile('C:/Users/fahad/.spyder-py3/untitled0.py', wdir='C:/Users/fahad/.spyder-py3')
Traceback (most recent call last):

File "<ipython-input-44-d1860d9262f7>", line 1, in <module>
runfile('C:/Users/fahad/.spyder-py3/untitled0.py', wdir='C:/Users/fahad/.spyder-py3')

File "C:\Users\fahad\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)

File "C:\Users\fahad\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/fahad/.spyder-py3/untitled0.py", line 9, in <module>
hh=np.loadtxt('hhrr1996221.txt', delimiter=',')

File "C:\Users\fahad\Anaconda3\lib\site-packages\numpy\lib\npyio.py", line 1092, in loadtxt
for x in read_data(_loadtxt_chunksize):
File "C:\Users\fahad\Anaconda3\lib\site-packages\numpy\lib\npyio.py",     line 1019, in read_data




   items = [conv(val) for (conv, val) in zip(converters, vals)]

  File "C:\Users\fahad\Anaconda3\lib\site-packages\numpy\lib\npyio.py", line 1019, in <listcomp>
items = [conv(val) for (conv, val) in zip(converters, vals)]

  File "C:\Users\fahad\Anaconda3\lib\site-packages\numpy\lib\npyio.py", line 738, in floatconv
return float(x)

ValueError: could not convert string to float: '2.0 264 264 244 252 504 252'

I would appreciate all the help i can, if you guys have a different code i can use please inform me and guide me through it.

Cheers.

Fahad
  • 11
  • 2

1 Answers1

3

Your delimiter is a space.

Try:

import numpy as np
hh=np.loadtxt(filename, delimiter=' ', skiprows=1)
time= hh[1:,0]
print( time )

Output:

[  2.10000000e+00   2.20000000e+00   2.30000000e+00 ...,   8.64027000e+04
   8.64028000e+04   8.64029000e+04]
Rakesh
  • 81,458
  • 17
  • 76
  • 113