Type error in read_csv() into the keyword

80 Views Asked by At

Pandas in the read_csv() in type error shown as:

TypeError                                 Traceback (most recent call last)
Cell In[30], line 1
----> 1 pd.read_csv('Datasets/BX-Books.csv', sep=';',encoding='latin-1',error_bad_lines=False)

TypeError: read_csv() got an unexpected keyword argument 'error_bad_lines'

I have trying to run code is usaally in error_bad_lines parameter and run the code:

pd.read_csv('Datasets/BX-Books.csv', sep=';',encoding='latin-1',error_bad_lines=False)

but pandas old version is running and work but why do not work it and through error:

TypeError                                 Traceback (most recent call last)
Cell In[30], line 1
----> 1 pd.read_csv('Datasets/BX-Books.csv', sep=';',encoding='latin-1',error_bad_lines=False)

TypeError: read_csv() got an unexpected keyword argument 'error_bad_lines'
1

There are 1 best solutions below

0
Mohsen_Fatemi On

According to the documentation this argument is deprecated and it was replaced by on_bad_lines argument. Here is the detail for this new argument :

on_bad_lines{‘error’, ‘warn’, ‘skip’} or Callable, default ‘error’

Specifies what to do upon encountering a bad line (a line with too many fields). Allowed values are :

'error', raise an Exception when a bad line is encountered.

'warn', raise a warning when a bad line is encountered and skip that line.

'skip', skip bad lines without raising or warning when they are encountered.

So you can use this parameter instead, here is an example of using this parameter in your code :

pd.read_csv('Datasets/BX-Books.csv', sep=';',encoding='latin-1',on_bad_lines='skip')