I have a text file that looks like this:
,Symbol,Date"+
",DRI,23/04/2021"+
",CQN,28/04/2021"+
",TGG,29/01/2021"+
and I want the result that looks like this:
"Symbol,Date"+
"DRI,23/04/2021"+
"CQN,28/04/2021"+
"TGG,29/01/2021"
I'm using pandas to convert csv to the text file above but I got this single double quote with comma right after (",) that I want to replace with only one single double quote (").
In the code below:
df = pd.read_csv(in_csv, na_filter=False, encoding='utf-8-sig')
# dict of replacements
replacements = {
'"",': '"'
}
# using the replace() method
df1 = df.replace(replacements, regex=True)
I tried many possible solutions like
1. '\"' to '"'
2. """," to """"
3. '\""," to '"'
...
but none seems to work. Doing this with Find and Replace in notepad is easy, but I need to automate this task by using code only. I'm also stuck at how to remove only that first comma and the last (+) sign without affecting the rest.
Could you suggest a solution to this problem I'm having?