Abhi
Abhi

Reputation: 1255

Extra enclosing quotes in pandas dataframe

I have a dataframe whose column shows extra quotes that enclose some of the records. Let's say col_a is a column which has multiple entries like ABC, DEF etc.

Some of the rows have ABC showing up as 'ABC' while others are present as ABC. Dataframe is sourced from a csv file. I opened the csv file manually and do not see any occurrences with quotes in the data.

I tried processing the data using str.replace("/'",'') function to remove single quotes but no luck. I am using this dataframe to group the data and publish results that calculates sum and other metrics. Since the quotes are additional characters, my aggregations are being broken down for same attribute value.

Is there a better way to handle these extra characters

Upvotes: 0

Views: 205

Answers (1)

moys
moys

Reputation: 8033

Use the below code to replace

df.replace ({'\'': ''}, regex=True, inplace=True)

Upvotes: 1

Related Questions