genfromtxt returning NaN rows

后端 未结 2 918
甜味超标
甜味超标 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 '<f8', 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)

    0 讨论(0)
  • 2021-01-18 04:54

    You should also add encoding=None to avoid having the Deprecated Warning:

    VisibleDeprecationWarning: Reading unicode strings without specifying the encoding argument is deprecated. Set the encoding, use None for the system default.

    Your line should be like:

    np.genfromtxt(txt, delimiter=',', names=True, dtype=None, encoding=None)
    
    0 讨论(0)
提交回复
热议问题