Ich versuche, ein PNG-Bild mit einigen CSV-Daten zu erstellen, aber ich bekomme einen Fehler in Bezug auf die Datumsspalte (mittlerweile in Liste konvertiert). Der Fehler ist:Convert CSV in PNG mit Matplotlib Problem
Traceback (most recent call last):
File "C:/Users/user1/Desktop/Py/AgentsStatus/testGraph.py", line 57, in <module>
plt.plot(dateCol,okCol,linewidth=5)
File "C:\Python34\lib\site-packages\matplotlib\pyplot.py", line 3154, in plot
ret = ax.plot(*args, **kwargs)
File "C:\Python34\lib\site-packages\matplotlib\__init__.py", line 1812, in inner
return func(ax, *args, **kwargs)
File "C:\Python34\lib\site-packages\matplotlib\axes\_axes.py", line 1425, in plot
self.add_line(line)
File "C:\Python34\lib\site-packages\matplotlib\axes\_base.py", line 1708, in add_line
self._update_line_limits(line)
File "C:\Python34\lib\site-packages\matplotlib\axes\_base.py", line 1730, in _update_line_limits
path = line.get_path()
File "C:\Python34\lib\site-packages\matplotlib\lines.py", line 925, in get_path
self.recache()
File "C:\Python34\lib\site-packages\matplotlib\lines.py", line 612, in recache
x = np.asarray(xconv, np.float_)
File "C:\Python34\lib\site-packages\numpy\core\numeric.py", line 482, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: could not convert string to float: '11-04-2016'
CSV enthält:
11-04-2016;37180;6;23852
18-04-2016;37341;9;24105
25-04-2016;37075;18;23788
Mein Code ist:
import csv
import matplotlib.pyplot as plt
import os
path = 'C:\\Users\\user1\\Desktop\\Py\\AgentsStatus\\data.csv'
with open (path) as csvfile:
readCSV = csv.reader(csvfile, delimiter=';')
dateCol = [] # date list
for row in readCSV:
if row:
date0 = row[0]
dateCol.append(date0)
with open (path) as csvfile:
readCSV = csv.reader(csvfile, delimiter=';')
okCol = [] # all agents list
for row in readCSV:
if row:
ok0 = row[1]
okCol.append(ok0)
with open (path) as csvfile:
readCSV = csv.reader(csvfile, delimiter=';')
heaCol = [] # healthy list
from matplotlib import pyplot as plt
from matplotlib import style
style.use('ggplot')
# can plot specifically, after just showing the defaults:
plt.plot(dateCol,okCol,linewidth=5)
plt.plot(dateCol,heaCol,linewidth=5)
plt.title('Epic Info')
plt.ylabel('Y axis')
plt.xlabel('X axis')
plt.show()
Mein Ziel ist es so etwas wie unten zu erstellen:
Könntest du mir bitte ein paar Tipps geben, was mache ich falsch? Ich denke mein Problem ist, dass ich die List dateCol nicht als Index für das Diagramm einstelle (um es nicht zu plotten). Könnten Sie mir bitte dabei helfen?
Vielen Dank.
'Ich erhalte eine Fehlermeldung zu dem Zeitpunkt column' in Verbindung stehend - Was ist der Fehler? – That1Guy
Hallo, sein ValueError: Konnte String in Float nicht konvertieren: '11 -04-2016 ' – Gonzalo
Das ist eine wichtige Information - schließen Sie den * gesamten Traceback * in Ihre Frage ein. – That1Guy