Reputation: 295
Hi I'm reading a file using
headers1 = pd.read_csv(file1, nrows=1).columns
This works well but the letter 'u' is appearing before every column header? It's definitely not in the original file. Any ideas where it came from or how I can get rid of it?
I'm guessing this means it's in unicode. I've tried to encode this to latin-1 but to no avail. Any suggestions?
Index([u'tLap', u'sLap', u'NLap', u'vCar'
Above is an example of the printed code before attempts to encode
headers1 = pd.read_csv(file1, nrows=1).columns
headers1.encode('latin-1')
print headers1
response
AttributeError: 'Index' object has no attribute 'encode'
Upvotes: 3
Views: 356
Reputation: 394299
You can safely ignore this, it just means the strings are unicode literals, they will not display with a u
prefix when you pass them as labels for plotting.
With respect to the error, headers1
is a Pandas.Index
object, if you want to encode them call the vectorised str.encode
method:
headers1.str.encode('latin-1')
but really this is unnecessary
Upvotes: 2