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=True, delimiter=',')
and the following comes out
(nan, nan, nan, nan, nan, nan, nan),
(nan, nan, nan, nan, nan, nan, nan),
(nan, nan, nan, nan, nan, nan, nan)],
dtype=[('name', '<f8'), ('severity', '<f8'), ('Message', '<f8'), ('AppDomainName', '<f8'), ('ProcessName', '<f8'), ('clientid', '<f8'), ('type', '<f8')])
dtype looks fine
and just to prove I'm not going crazy I tried this code
import csv
f = open('errors.csv', 'rt')
reader = csv.reader(f)
data = []
for r in reader:
data.append(r)
f.close()
which works great, but im trying to figure out whats the deal with genfromtxt
here is a sample from the csv
name,severity,Message,AppDomainName,ProcessName,clientid,type
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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With