0

My text file (test.out) contains data arrangement are in three rows but the number of columns are different in each row. That is like shown below

2013  531 1155 24.0 L  19.219  76.766  0.2  JOY  3 0.0 0.4LJOY                1
CBN  SZ IPg      1155 26.58                              87    0.0110 15.1 134
CBN  SN ESg      1155 28.38                              87   -0.0210 15.1 134 

It showing error while loading the data using import numpy as np

d1=np.genfromtxt('test.out', dtype=str)

it shows error message: raise ValueError(errmsg)

ValueError: Some errors were detected !
    Line #2 (got 9 columns instead of 13)
    Line #3 (got 9 columns instead of 13)

How it can be loaded using numpy genfromtxt. If anybody can help it will be great help for me. Thanks in advance.

furas
  • 134,197
  • 12
  • 106
  • 148
  • maybe read it as normal text file using standard `open()`, `read()`, `close()` and parse it on your own. – furas Feb 19 '21 at 14:54
  • `numpy array` (and `pandas FataFrame`) are for tables which have the same number of data in every row (columns). How did you expect to keep this data in numpy array? – furas Feb 19 '21 at 14:58
  • Thanks for response, Dear Furas. After removing the field space by ',' of test.out file using shell"s script. I find the below commands is useful for the range of columns np.genfromtxt(a, dtype=str, delimiter=',', usecols=np.arange(0,8)) Thank you – Chittaranjan Mahato Feb 19 '21 at 16:14

0 Answers0