genfromtxt returning NaN rows

后端 未结 2 917
甜味超标
甜味超标 2021-01-18 04:21

I am trying to read a csv file with numpy and I have the following code

from numpy import genfromtxt
data = genfromtxt(open(\'errerr.csv\', \"r\"), names=Tr         


        
2条回答
  •  鱼传尺愫
    2021-01-18 04:37

    Your dtype isn't fine. It's specifying ', a float, for each of the fields. You want strings. Try dtype=None:

     np.genfromtxt(txt,delimiter=',',names=True,dtype=None)
    

    which produces:

    array([ ('Strings strings', 'Error', '")  Thread Name:  Extended Properties:"', 'SunDSrvc.exe', 'C:\\Program Files\\SunDSrvc.exe', '5DAA9377 ', 'Client'),
           ('Strings strings', 'Error', '")  Thread Name:  Extended Properties:"', 'SunDSrvc.exe', 'C:\\Program Files\\SunDSrvc.exe', '5DAA9377 ', 'Client'),
           ('Strings strings', 'Error', '")  Thread Name:  Extended Properties:"', 'SunDSrvc.exe', 'C:\\Program Files\\SunDSrvc.exe', '5DAA9377 ', 'Client')], 
          dtype=[('name', 'S15'), ('severity', 'S5'), ('Message', 'S39'), ('AppDomainName', 'S12'), ('ProcessName', 'S29'), ('clientid', 'S9'), ('type', 'S6')])
    

    (I have removed extraneous stuff about delimiters within quotes)

提交回复
热议问题