replace single quote to double quote python pandas dataframe
If the problem is converting the single quote to double quotes without the restraint of doing it after you read it into a dataframe - you could change the .csv
file before you read it into a dataframe:
$ sed -i "s/'/\"/g" file_name.csv
If you have to replace them after you read them into a dataframe, try the solution mentioned in this post:
df.replace({'\'': '"'}, regex=True)
replacing quotes, commas, apostrophes w/ regex - python/pandas
You can use str.replace
:
test['Address 1'] = test['Address 1'].str.replace(r"[\"\',]", '')
Sample:
import pandas as pd
test = pd.DataFrame({'Address 1': ["'aaa",'sa,ss"']})
print (test)
Address 1
0 'aaa
1 sa,ss"
test['Address 1'] = test['Address 1'].str.replace(r"[\"\',]", '')
print (test)
Address 1
0 aaa
1 sass
Related Topics
Python Read File Determined by Separator \R\N
Using Continue in a Try and Except Inside While-Loop
Getting the Bounding Box of the Recognized Words Using Python-Tesseract
Stripping Whitespaces from a List Inside the List of Tuples
Django Viewset Has Not Attribute 'Get_Extra_Actions'
How to Tell If Tensorflow Is Using Gpu Acceleration from Inside Python Shell
Sum of Square Differences (Ssd) in Numpy/Scipy
Count Number of Empty Array Occurrences Within a 2D Array
Pandas: How to Return Rows Where a Column Has a Line Breaks/New Line ( \N ) in Its Cell
Python - Using Regex to Find Multiple Matches and Print Them Out
Increment Values in a List of Lists Starting from 1
Python Command Not Working in Command Prompt
Key Error: None of [Int64Index...] Dtype='Int64] Are in the Columns
How to Get a Random Value from Dictionary
Pandas - Find Index of Value Anywhere in Dataframe