I am trying to remove single quotes from data that is within a bucket before dumping the values to big query. I have tried using str.replace but this is not working for me.. here is the code
all_dat = pd.DataFrame()
for blob in blobs:
dat = pd.read_csv("gs://{}/{}".format(bucket_name, blob.name))
all_dat = all_dat.append(dat, ignore_index=True)
all_dat = all_dat.replace('"', "")
all_dat.columns=column_names
print(all_dat)
The data that I am trying to remove the single quotes from looks like this
Fresh_ID Simpler_ID Name
'87008' '000280' JaneDoe
I am trying to remove the single quotes so that I can just have the values without the single quotes in them, of which the end output will be
Fresh_ID Simpler_ID Name
87008 000280 JaneDoe
CodePudding user response:
You could try:
df["Fresh_ID"] = df["Fresh_ID"].str.replace(r"^'|'$", "")
and so on for all the columns. The regex pattern ^'|'$
will match single quote at either the beginning or ending of the column value.
CodePudding user response:
Another option would be
df["Fresh_ID"] = df["Fresh_ID"].str.strip("'")