0

I have built a random forest model using sklearn and python to predict 'pages' from various 'size' features. In my testing and training data, the column headers are 'pages' and 'size', but in my new data I want to feed through my model to get the predictions, the column headers are 'p' and 's', rather than 'pages' and 'size'. I was wondering if there is anyway to read these as 'pages' and 'size' so that my model works correctly. Thank you so much!

ForceBru
  • 43,482
  • 10
  • 63
  • 98
  • Does this answer your question? [Renaming columns in pandas](https://stackoverflow.com/questions/11346283/renaming-columns-in-pandas) – Nicolas Gervais Jun 19 '20 at 17:42

2 Answers2

0

You can add another column with new name to original dataframe and drop the old ones.

df['p'] = df['pages']

df['s'] = df['sizes']

df = df.drop(['pages','sizes'],axis=1)
Vijeth Rai
  • 321
  • 2
  • 10
0

You can simply use df.rename:

df.rename(columns={'p':'pages', 's', 'sizes'}

I hope this will help you!

Emanuele
  • 174
  • 13