Fix pandas.errors.ParserError: Error tokenizing data. C error for Beginners – Pandas Tutorial

By | October 8, 2019

Python pandas library can allow us to load data from csv files, however, when you are loading data, you may find this error: pandas.errors.ParserError: Error tokenizing data. C error. In this tutorial, we will introduce how to fix this error.

Create a csv file

We have created a csv file called pandas_csv.csv, we will add some data in this csv file.

Open this file with excel

Many computers open csv files with microsoft excel application defaultly, we also open this csv file with excel and add some data.

open csv file with excel

Load csv data with pandas

We will use pandas to load csv data into pandas dataframe.

import pandas as pd

csv_file = 'pandas_csv.csv'
df = pd.read_csv(csv_file)

Then you will find this ParserError.

pandas.errors.ParserError - Error tokenizing data. C error

Open this csv file with notepad

Notepad is a good text editor, we use it to open this csv file. You may find

open csv with notepad

data in this csv file is garbled. Which tell us we should add our data with notepad, not excel.

Add data with notepad

We open our csv file with notepad and add our data int this file.

add data into csv file with notepad

Then load data with pandas again, we will get result like this:

0   80.0%\t81.20%
1  81.20%\t83.10%
2   81.6%\t83.40%
3   84.2%\t84.25%
4   82.6%\t80.30%
5  85.10%\t81.20%

This error is fixed.

Leave a Reply

Your email address will not be published. Required fields are marked *