ich eine CSV-Datei zu lesen, frmo die erhalte ich diese Spalten:Pandas - Spalte nicht in Datenrahmen gefunden
encoding = "UTF-8-SIG"
csv_file = "my/path/to/file.csv"
fields_cols_mapping = {
'brand_id': 'Brand',
'custom_dashboard': 'Custom Dashboard LO',
'custom_dashboard_isfeatured': 'Custom Dashboard LO - Is Featured',
'description': 'LODescription',
'is_active': 'TrainingIsActive',
'lo_id': 'LOID',
'lo_type_id': 'LOType',
'timestamp': 'Timestamp',
'title': 'LOTitle',
'training_version_id': 'TrainingVersion'
}
dataframe = pd.read_csv(
csv_file,
encoding=encoding,
sep='|',
usecols=[unicode(v) for v in fields_cols_mapping.values()],
dtype={ k: object for k in fields_cols_mapping.keys() },
)
Während jedoch mit IPDB Inspektion fand ich, dass der Parser mit read_csv
genannt konvertiert nicht der Spaltenname Custom Dashboard LO – Is Featured
:
# debug
> /../../venvs/myvenv/lib/python2.7/site-packages/pandas/io/parsers.py(1140)__init__()
1138 col_indices = []
1139 for u in self.usecols:
-> 1140 if isinstance(u, string_types):
1141 col_indices.append(self.names.index(u))
1142 else:
ipdb> self
<pandas.io.parsers.CParserWrapper object at 0x10b134710>
ipdb> self.names
[u'LOType', u'LOID', u'LOTitle', u'TrainingVersion', u'LODescription', u'TrainingIsActive', u'Custom Dashboard LO', u'Brand', u'Custom Dashboard LO \u2013 Is Featured', u'Timestamp']
Hat jemand irgendwelche Vorschläge, was ich tun sollte?