Reputation: 45
I have CSV file containing below string as a field value for one column
It's Time. Say "I Do" in my Style.
So I want to convert double quote (") into single quote (')
expected output string: It's Time. Say 'I Do' in my Style.
I want to replace thing and save modified data in the same CSV file.
Can you I use regex using python?
Upvotes: 1
Views: 2261
Reputation: 7108
Here is what you need:
with open('C:/path/to/csv', 'r') as f: // open in read mode
text = f.read() // read and save the text of file in a variable
converted_text = text.replace('"', "'") // replace characters, regex not required here, but this is where you will use it if required
with open('C:/path/to/csv', 'w') as f: // open in write mode now
f.write(converted_text) // write the file. Old data in the file will be removed
Upvotes: 1