1

Error Generated: UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)

Data Example:
2014-08-06 7:00,4.06E+04,42878.05892
2014-08-06 8:00,4.40E+04,42857.00667

I followed this accepted answer but haven't had any luck making it work: timestamps passed to matplotlib.date2num: 'str' object has no attribute 'toordinal'

Code:

timeformat = '%Y-%m-%d %H:%M'
columns = ["Datetime","Prediction","Actual"]
dtypes = ["object","float","float"]
myResults1 = np.genfromtxt("/Users/project/results_1.csv", delimiter=",", names=columns, dtype=dtypes)

time = [datetime.strptime(i,timeformat) for i in myResults1['Datetime']]
predictions = myResults1['Prediction']
actual = myResults1['Actual']
fig = pyplot.figure()
ax1 = fig.add_subplot(3,2,1,axisbg='grey')
ax1.plot_date(time,predictions)
ax1.set_xlabel('Time')
ax1.set_ylabel('Prediction')
pyplot.setp(ax1.xaxis.get_majorticklabels(),rotation=25)

Thanks anyone who can help!!

lsch91
  • 335
  • 3
  • 11
  • Have you tried `.encode('utf-8')` for your text? – Mehdi Saman Booy Jan 23 '18 at 20:43
  • @mehD something like this? infile = "/Users/project/results_1.csv" #myResults1 = np.genfromtxt([infile.encode('utf-8)], delimiter=",", names=columns, dtype=dtypes) error generated: ValueError: could not assign tuple of length 1 to structure with 3 fields. – lsch91 Jan 23 '18 at 20:55
  • No. It is used for converting a string to utf-8 one. For example I think you should something like this: time = [datetime.strptime(i,timeformat).encode('utf-8') for i in myResults1['Datetime']] – Mehdi Saman Booy Jan 25 '18 at 06:06

0 Answers0