Sicher bin ich etwas fehlt offensichtlich - aber ich bin von diesem Ergebnis verblüfft:Python 2.7 Pandas Dataframe.from_csv Spalte Datum nicht zugänglich
Umwelt:
Ubuntu 16.04.1 LTS Python 2.7.12 Pandas 0.18.1
CSV-Datei:
Date,Open,High,Low,Close,Volume
12-Aug-16,107.78,108.44,107.78,108.18,18660434
11-Aug-16,108.52,108.93,107.85,107.93,27484506
10-Aug-16,108.71,108.90,107.76,108.00,24008505
Code:
import pandas as pd
aapl = pd.DataFrame.from_csv('aapl.csv',index_col=None)
print aapl.columns
print aapl.Low.dtype
print aapl['Low'].dtype
# Fails - KeyError
print aapl['Date'].dtype
Ausgang:
Index([u'Date', u'Open', u'High', u'Low', u'Close', u'Volume'], dtype='object')
float64
float64
KeyError: 'Date'
Das mir Geheimnis ist, dass ‚Datum‘ in der Liste Spalten angezeigt wird, aber ich kann nicht die Spaltenadresse. Was vermisse ich?
Ich wette, Ihre Datei ist UTF8 mit BOM encoded – Boud
Ich denke Sie Ich bin mir nicht sicher, was die Codierung ist, aber da sind definitiv Sonderzeichen drin. print repr (aapl.columns [0]) ergibt '\ xef \ xbb \ xbfDate'. Danke –