Typeerror Occours When I Tried To Get A Graphic From Csv File In Python
import os from matplotlib import pyplot as pyplot from collections import defaultdict import csv import numpy as np path = r'C:\Users\AK6PRAKT\Desktop\6daten' dirs = os.listdir(pat
Solution 1:
This error code results from an attempt to cast a numpy array to float, which has length > 1:
Example:
float(np.array([3,2,1]))
Traceback (most recent calllast):
File "<ipython-input-22-e396216bb2ea>", line 1, in<module>float(np.array([3,2,1]))
TypeError: only length-1 arrays can be converted to Python scalars
but:
float(np.array([3]))
: 3.0So this error occurs in your line (44, to cite the error message)
y.append(float(list_temp2))
in case of list_temp2 has more than one entry. So it should have nothing to do with how many files you process.
However:
Like Georgy already mentioned - let's say your code is a little more complicated than the task requires. Here just a few thoughts of mine...
- if you need a list of all
csv-files in a directory, did you have alook at python'sglob-module? It's capable of searching subdirectories, too... - You iterate over a file for reading, again for writing without lines which contain "Date" and then again you read it it again...? That's too much, IIUC. Couldn't you just use the last loop and put your list_temp-stuff there in a conditional, which tests for "contains 'Date'"?
- Why do you
fig = pyplot.figure(figsize=(10,10))right beforeplt.show()at the end? This should lead to an unused empty figure. headerremover.pycombined with your loop andif 'Date' not in rowlooks like if there are many header lines, also in the middle, in your files - is that true? Because if you just would have a header section of n lines at the top of each file, there would be again much simpler ways to skip these lines...
Post a Comment for "Typeerror Occours When I Tried To Get A Graphic From Csv File In Python"