Reputation: 134
I imported a data frame in python with pandas. But I have column names with strange encoding.
colnames = ['Price \xe2\x82\xac', 'x-rate \xe2\x82\xac/$']
Can you help me to decode these column names?
Upvotes: 2
Views: 1044
Reputation: 9019
Try the following:
colnames = [i.encode('raw_unicode_escape').decode('utf-8') for i in colnames]
Yields:
['Price €', 'x-rate €/$']
Per @piRSquared's comment, you can do this with pandas
using:
df.rename(columns=lambda x: x.encode('raw_unicode_escape').decode())
Upvotes: 5