0

Running the following code in Python 2.7:

import numpy as np
import pandas as pd

dates = pd.date_range('20190102', periods=6)
df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=list('ABCD'))
print df.columns

produces this output:

Index([u'A', u'B', u'C', u'D'], dtype='object')

From other sources I gather that these are unicode labels. How do I get rid of them?

Forklift17
  • 2,245
  • 3
  • 20
  • 32

2 Answers2

1

df.columns = [str(col_name) for col_name in df.columns]

More information can be found in this answer:

Removing u in list

0

you can also use 'str()' on the parsed data

Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81