Skip to content

Instantly share code, notes, and snippets.

@smram
Created October 4, 2017 23:35
Show Gist options
  • Save smram/d6ded3c9028272360eb65bcab564a18a to your computer and use it in GitHub Desktop.
Save smram/d6ded3c9028272360eb65bcab564a18a to your computer and use it in GitHub Desktop.
[pandas] replace newlines,tabs,carriage returns in fields
# got to handle both escaped and literal
df.replace(to_replace=[r"\\t|\\n|\\r", "\t|\n|\r"], value=["",""], regex=True, inplace=<INPLACE>)
@jvioladevelops
Copy link

can you break down this code or provide a reference? Thank you!

@kwright15
Copy link

This also worked for me! And I had also tried many suggestions from StackOverflow that did not work. Thank you!

@sktzofrenic
Copy link

I got typeError: Cannot compare types 'ndarray(dtype=int64)' and 'str' on one of the rows in the database table

@MarceloCorrales
Copy link

with inplace=False worked like a charmed, with =True it didn't let me do the "to_CSV". anyway, problem solved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment