0

I am using Anaconda to read table from hive and all my column names have been automaticly added a prefix like test.age,test.sex,test.degree... How to use pandas to erase all the prefix 'test.'?

LeeKing
  • 71
  • 1
  • 7
  • You don't show any evidence of what you've tried in order to address this problem, which is the reason I haven't provided an answer. I suggest you look at the `pandas.DataFrame.columns` attribute – Andrew Dec 05 '18 at 09:17
  • kindly provide what you have tried. – Ashutosh Sep 23 '19 at 14:02

2 Answers2

5

one way to do it is:

df.columns = [i.replace("test.", "") for i in df.columns]
Sociopath
  • 13,068
  • 19
  • 47
  • 75
3
df.columns = [i[1] for i in df.columns.str.split('.')]
meW
  • 3,832
  • 7
  • 27