Hier ist ein Code, den ich zuvor erstellt habe.Wie transformiere ich die CSV-Liste in int?
import sys,csv
from matplotlib import pyplot
from time import sleep
import numpy as ma
import pandas
import serial
file = open("C:/Users/rickchen/Desktop/MQTT1/testfile.csv")
book = csv.reader(file)
b=list(book)
print b
print type(b)
fand ich, dass das Ergebnis wie, dass es Zeichenfolge,
[['114', '119', '116', '118', '120', '118', '113', '118', '121', '122', '117', '114', '112', '114', '115', '120', '128', '128', '120', '112', '110', '117', '122', '118', '112', '113', '122', '120', '116', '114', '118', '117', '128', '132', '130', '112']]
<type 'list'>
ist und nicht verwendet werden kann, um aufgetragen werden.
so, ich meine, einen neuen Code aus diesem Problem
import sys,csv
from matplotlib import pyplot
from time import sleep
import numpy as ma
import pandas
import serial
file = open("C:/Users/rickchen/Desktop/MQTT1/testfile.csv")
book = csv.reader(file)
b=list(book)
c=[]
for bx in b:
c.append(int(bx))
print c
print type(c)
zu lösen, aber es zeigt Typeerror: int() Argument ein String oder eine Zahl sein muss, nicht 'Liste'
So Ich möchte wissen, wie ich dieses Problem lösen kann. Kann Herr mir einen Vorschlag geben? Ich danke dir sehr!!
'b = [int (e) für e in b] ' – martijnn2008
' Buch = [int (line.strip()) für Zeile in csv.reader (Datei)] sollte direkt funktionieren. – FabienP
Ist das '.strip() nicht sinnlos? – martijnn2008