I have a CSV file that has a column ID and Name. For example:
ID| Name
1 | ['John Mark']
What I want to happen is to remove the [''] from the name. I tried using str.strip
but it only removes the brackets.
I'm only a beginner so sorry.
I have a CSV file that has a column ID and Name. For example:
ID| Name
1 | ['John Mark']
What I want to happen is to remove the [''] from the name. I tried using str.strip
but it only removes the brackets.
I'm only a beginner so sorry.
Pandas series supports string operations. For example;
data_set['Name'] = data_set['Name'].str.replace("['", "")
data_set['Name'] = data_set['Name'].str.replace("']", "")
Is it best practice? Not sure. But should work.
data = [[1,"['John Mark']"]]
df = pd.DataFrame(data, columns = ["ID","Name"])
ID Name
0 1 ['John Mark']
Replace can accept a regex pattern.
>>> df["Name"].str.replace("^\['|'\]$","")
0 John Mark
Name: Name, dtype: object
In case it's not a single quote:
>>> df["Name"].str.replace("^\[.|.\]$","")
0 John Mark
Name: Name, dtype: object