1

I have a CSV file that have this line:

"Venta presencial",53232907737,"[{"was_pin":false,"pin_validation":"pin_not_validated","integration":"none","is_fallback":false}]"

When I read the file with read_csv:

df = pd.read_csv(filename,encoding='utf-8')

I expect 3 columns, but I receive 6 columns

I need to ignore the separator "," when its inside of double quotes.

Jamiu S.
  • 5,257
  • 5
  • 12
  • 34
  • Does this answer your question? [numpy genfromtxt/pandas read\_csv; ignore commas within quote marks](https://stackoverflow.com/questions/24079304/numpy-genfromtxt-pandas-read-csv-ignore-commas-within-quote-marks) – KetZoomer Jan 04 '23 at 14:54
  • Can ' " ' be " ' " ? – Shounak Das Jan 04 '23 at 15:23

1 Answers1

1

Based on this Answer, Try this:

import pandas as pd
from io import StringIO
import re

for_pd = StringIO()
with open(f'PATH/csv1.csv') as file:
    for line in file:
        new_line = re.sub(r',', '|', line.rstrip(), count=2)
        print (new_line, file=for_pd)

for_pd.seek(0)

df = pd.read_csv(for_pd, sep='|', names=["A","B","C"])
df.head()
Niyaz
  • 797
  • 1
  • 8
  • 18