genfromtxt导入一个txt文件的问题

时间:2017-08-15 17:31:54

标签: linux numpy genfromtxt

我有一个顶级名称的数据文件:

    position        avgx        avgy        avgz        stdx        stdy        stdt        avgG    nemixrms    nemiyrms    nemirrms        rmax
 2.800e+00 -4.997e-05 -1.373e-04  2.800e+00  2.812e-03  2.819e-03  4.641e-10  1.684e+00  7.433e-06  7.377e-06  7.404e-06  1.224e-02
 2.750e+00 -3.592e-05 -1.040e-04  2.750e+00  2.110e-03  2.129e-03  4.634e-10  1.684e+00  6.412e-06  6.361e-06  6.386e-06  9.652e-03
 2.700e+00 -2.209e-05 -7.128e-05  2.700e+00  1.457e-03  1.485e-03  4.627e-10  1.684e+00  5.346e-06  5.338e-06  5.342e-06  7.083e-03
 2.650e+00 -8.730e-06 -4.000e-05  2.650e+00  8.753e-04  9.082e-04  4.620e-10  1.684e+00  4.352e-06  4.439e-06  4.395e-06  4.591e-03
 2.600e+00  4.074e-06 -1.208e-05  2.600e+00  4.273e-04  4.515e-04  4.613e-10  1.683e+00  3.728e-06  3.968e-06  3.846e-06  3.210e-03
 2.590e+00  6.587e-06 -7.411e-06  2.590e+00  3.688e-04  3.880e-04  4.612e-10  1.683e+00  3.675e-06  3.941e-06  3.805e-06  3.183e-03
 2.550e+00  1.580e-05  5.137e-06  2.550e+00  3.594e-04  3.587e-04  4.606e-10  1.683e+00  3.741e-06  4.020e-06  3.878e-06  3.100e-03
 2.500e+00  2.600e-05  1.130e-05  2.500e+00  7.696e-04  7.677e-04  4.600e-10  1.684e+00  4.343e-06  4.436e-06  4.389e-06  3.939e-03
 2.450e+00  3.586e-05  1.554e-05  2.450e+00  1.358e-03  1.353e-03  4.593e-10  1.684e+00  4.701e-06  4.760e-06  4.730e-06  5.477e-03
 2.400e+00  4.561e-05  1.929e-05  2.400e+00  2.027e-03  2.018e-03  4.587e-10  1.684e+00  4.907e-06  4.993e-06  4.874e-06  7.949e-03
 2.350e+00  5.562e-05  2.210e-05  2.350e+00  2.746e-03  2.731e-03  4.580e-10  1.684e+00  8.541e-06  8.710e-06  4.954e-06  1.051e-02
 2.250e+00  7.616e-05 -3.145e-06  2.250e+00  4.084e-03  4.011e-03  4.567e-10  1.684e+00  1.881e-04  1.882e-04  5.092e-06  1.489e-02
 2.200e+00  6.767e-05 -2.592e-05  2.200e+00  4.086e-03  4.011e-03  4.561e-10  1.684e+00  8.753e-05  8.755e-05  5.263e-06  1.456e-02
 2.150e+00  5.840e-05 -2.875e-05  2.150e+00  3.881e-03  3.818e-03  4.555e-10  1.684e+00  1.502e-05  1.496e-05  5.555e-06  1.345e-02
 2.050e+00  4.430e-05 -2.326e-05  2.050e+00  3.528e-03  3.479e-03  4.543e-10  1.684e+00  6.266e-06  6.305e-06  6.283e-06  1.120e-02
 2.000e+00  3.752e-05 -1.994e-05  2.000e+00  3.393e-03  3.350e-03  4.537e-10  1.684e+00  6.618e-06  6.664e-06  6.639e-06  1.009e-02
 1.950e+00  3.073e-05 -1.661e-05  1.950e+00  3.287e-03  3.249e-03  4.531e-10  1.684e+00  6.944e-06  6.988e-06  6.964e-06  9.006e-03
 1.900e+00  2.391e-05 -1.328e-05  1.900e+00  3.211e-03  3.180e-03  4.526e-10  1.684e+00  7.227e-06  7.265e-06  7.243e-06  7.935e-03

我正在使用numpy.genfromtxt将此数据文件导入为

screendata=genfromtxt('../screen.txt',delimiter=',',names=True,dtype=None)

如果我打印screendata,它会告诉我:

[ (b'2.800e+00 -4.997e-05 -1.373e-04  2.800e+00  2.812e-03  2.819e-03  4.641e-10  1.684e+00  7.433e-06  7.377e-06  7.404e-06  1.224e-02',)
 (b'2.750e+00 -3.592e-05 -1.040e-04  2.750e+00  2.110e-03  2.129e-03  4.634e-10  1.684e+00  6.412e-06  6.361e-06  6.386e-06  9.652e-03',)
 (b'2.700e+00 -2.209e-05 -7.128e-05  2.700e+00  1.457e-03  1.485e-03  4.627e-10  1.684e+00  5.346e-06  5.338e-06  5.342e-06  7.083e-03',)
 (b'2.650e+00 -8.730e-06 -4.000e-05  2.650e+00  8.753e-04  9.082e-04  4.620e-10  1.684e+00  4.352e-06  4.439e-06  4.395e-06  4.591e-03',)
 (b'2.600e+00  4.074e-06 -1.208e-05  2.600e+00  4.273e-04  4.515e-04  4.613e-10  1.683e+00  3.728e-06  3.968e-06  3.846e-06  3.210e-03',)
 (b'2.590e+00  6.587e-06 -7.411e-06  2.590e+00  3.688e-04  3.880e-04  4.612e-10  1.683e+00  3.675e-06  3.941e-06  3.805e-06  3.183e-03',)
 (b'2.550e+00  1.580e-05  5.137e-06  2.550e+00  3.594e-04  3.587e-04  4.606e-10  1.683e+00  3.741e-06  4.020e-06  3.878e-06  3.100e-03',)
 (b'2.500e+00  2.600e-05  1.130e-05  2.500e+00  7.696e-04  7.677e-04  4.600e-10  1.684e+00  4.343e-06  4.436e-06  4.389e-06  3.939e-03',)

我尝试获取colume数据,如:

screendata['position']

显示错误消息

      print(screendata['position'])
ValueError: field named position not found

然后,我试过

print(screendata.dtype.names)

('position________avgx________avgy________avgz________stdx________stdy________stdt________avgG____nemixrms____nemiyrms____nemirrms________rmax',)

我怎么能将这种数据导入python,我可以在colume模式下操作? 谢谢!

0 个答案:

没有答案