jcoke
jcoke

Reputation: 1891

Replacing special characters not working in Pandas

I am trying to remove special characters from a string, but when I export the Pandas dataframe as a CSV, I can still see the special characters.

Does anyone know why that is?

Current Code:

document = json.dumps(jfile,default=str)
document2 = re.sub("[“â£$€™]", '', document)
document2  = json.loads(document2)
document2.to_csv("test.csv", index = False)

Output (special character still found in CSV file):

enter image description here

Upvotes: 0

Views: 185

Answers (1)

Mahery Ranaivoson
Mahery Ranaivoson

Reputation: 450

This seems the pandas Encoding problem. Try to read/load your file with the appropriate encoding.

Upvotes: 2

Related Questions