我有一个巨大的文本文件It is the second txt file labeled hhrr1996221.txt.zip
我试图通过计数与时间分析数据,时间从2毫秒开始,然后给出6个数据集(计数)并重复。
自去年以来我没有使用过python,虽然我确实希望提高我的编码技巧。我使用了以下代码:
import numpy as np
hh=np.loadtxt('hhrr1996221.txt', delimiter=',')
time= hh[1:,0]
我只是想测试一下,如果我得到一个数组,我最终也想得到计数,然后绘制图表
我得到的错误信息是
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'
我很感激所有的帮助,如果你们有不同的代码我可以使用,请告诉我并指导我完成它。
干杯。
答案 0 :(得分:2)
您的分隔符是一个空格。
<强>尝试:强>
import numpy as np
hh=np.loadtxt(filename, delimiter=' ', skiprows=1)
time= hh[1:,0]
print( time )
<强>输出:强>
[ 2.10000000e+00 2.20000000e+00 2.30000000e+00 ..., 8.64027000e+04
8.64028000e+04 8.64029000e+04]