Search code examples
stringdataframeintegerdata-preprocessing

Doing Apply(str) to int creates a bunch of \n's?


I have a dataframe like this labeled by year:

enter image description here

I would like to change these ints to strs because they are actually categorical variables. However, this is the result:

X_train['YrSold'] = X_train['YrSold'].apply(str)

enter image description here

I would prefer to get rid of all those \n's automatically in the .apply(str) process, as opposed to postprocessing each column via regex. Seems like the latter would have more room for error.


Solution

  • Solution was astype(str) instead of apply(str)