1

I cannot get this to replicate outside of this file, since if I try it on a string myself it works, but for some reason not in my dataframe.

I just want to get rid of the '\n' characters in my strings, but its not working, as seen below.

enter image description here

I've tried the following, with no success

UseCaseMethodsCols.apply(lambda x: ' ' if '\n' in x else x)
UseCaseMethodsCols = UseCaseMethodsCols.replace(r'\n', ' ').replace(r'\r', '')

AxW
  • 582
  • 1
  • 6
  • 20
  • If it's an actual newline you shouldn't use a raw string as `r'\n'` is a \ followed by an `n` – Nick Mar 20 '21 at 23:22
  • [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). Please read [mre]. – wwii Mar 20 '21 at 23:25

1 Answers1

1

Try adding regex=True to the replace calls:

UseCaseMethodsCols = UseCaseMethodsCols.replace(r'\n', ' ', regex=True)
tdy
  • 36,675
  • 19
  • 86
  • 83