Pandas - column not found in dataframe
<p>I'm reading a csv file, frmo which I obtain these columns:</p>

<pre><code>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() },
    )
</code></pre>

<p>However, while inspecting with ipdb I found that the parser called with <code>read_csv</code> doesn't convert the column name <code>Custom Dashboard LO â Is Featured</code>:</p>

<pre><code># debug
&gt; /../../venvs/myvenv/lib/python2.7/site-packages/pandas/io/parsers.py(1140)__init__()
1138             col_indices = []
1139             for u in self.usecols:
-&gt; 1140                 if isinstance(u, string_types):
1141                     col_indices.append(self.names.index(u))
1142                 else:

ipdb&gt; self
&lt;pandas.io.parsers.CParserWrapper object at 0x10b134710&gt;
ipdb&gt; 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']
</code></pre>

<p>Does anybody have any suggestions about what I should do?</p>

<p>Your problem is that the dash in the dataframe isn't the same as the dash in the dictionary.  The one in the dataframe is an en dash (<code>â</code> or <code>\u2013</code>), while the one in your dictionary is a hyphen (<code>â</code> or <code>\u2010</code>).  They look similar, but they're not the same character, so the strings don't match.</p>

python pandas utf-8