Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9206507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:11:26+00:00 2026-06-18T00:11:26+00:00

I am trying to read a csv file using pandas and the file has

  • 0

I am trying to read a csv file using pandas and the file has a column called Tags which consist of user provided tags and has tags like – , “”, ”,1950’s, 16th-century. Since these are user provided, there are many special characters which are entered by mistake as well. The issue is that I cannot open the csv file using pandas read_csv. It shows error:Cparser, error tokenizing data. Can someone help me with reading the csv file into pandas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:11:27+00:00Added an answer on June 18, 2026 at 12:11 am

    Okay. Starting from a badly formatted CSV we can’t read:

    >>> !cat unquoted.csv
    1950's,xyz.nl/user_003,bad, 123
    17th,red,flower,xyz.nl/user_001,good,203
    "",xyz.nl/user_239,not very,345
    >>> pd.read_csv("unquoted.csv", header=None)
    Traceback (most recent call last):
      File "<ipython-input-40-7d9aadb2fad5>", line 1, in <module>
        pd.read_csv("unquoted.csv", header=None)
    [...]
      File "parser.pyx", line 1572, in pandas._parser.raise_parser_error (pandas/src/parser.c:17041)
    CParserError: Error tokenizing data. C error: Expected 4 fields in line 2, saw 6
    

    We can make a nicer version, taking advantage of the fact the last three columns are well-behaved:

    import csv
    
    with open("unquoted.csv", "rb") as infile, open("quoted.csv", "wb") as outfile:
        reader = csv.reader(infile)
        writer = csv.writer(outfile)
        for line in reader:
            newline = [','.join(line[:-3])] + line[-3:]
            writer.writerow(newline)
    

    which produces

    >>> !cat quoted.csv
    1950's,xyz.nl/user_003,bad, 123
    "17th,red,flower",xyz.nl/user_001,good,203
    ,xyz.nl/user_239,not very,345
    

    and then we can read it:

    >>> pd.read_csv("quoted.csv", header=None)
                     0                1         2    3
    0           1950's  xyz.nl/user_003       bad  123
    1  17th,red,flower  xyz.nl/user_001      good  203
    2              NaN  xyz.nl/user_239  not very  345
    

    I’d look into fixing this problem at source and getting data in a tolerable format, though. Tricks like this shouldn’t be necessary, and it would have been very easy for it to be impossible to repair.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read a csv file into R that has date values in
I am trying to read and sort a csv file that has data that
I am trying to read a very simple but somehow large(800Mb) csv file using
To simplify, I'm trying to read the content of a CSV-file using the ifstream
I am trying to read a CSV file using PHP. I want to use
I'm trying to generate Item IDs using StreamReader on my .CSV file (It has
I am trying to read a file using csv.DictReader I have a field that
I am trying to read a CSV file in R (under linux) using read.csv().
Using Android (Eclipse) I am trying to read a .csv file and dynamically populate
I'm trying to print a CSV file using certain column widths. I think there's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.