Tutorial Example

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

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.

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)
print(df)

Then you will find this ParserError.

Open this csv file with notepad

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

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.

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

       Acc1\tAcc2
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.