Read_csv() got an unexpected keyword argument ‘on_bad_lines’

The error message “read_csv() got an unexpected keyword argument 'on_bad_lines'” in Python occurs when the function read_csv() is called with an invalid or unrecognized argument.

This error typically happens when you are using an outdated version of the pandas library, as the 'on_bad_lines' argument was introduced in later versions.

To fix this issue, you can either update your pandas library to the latest version or remove the 'on_bad_lines' argument from your call to read_csv().

Examples:

# Example 1: Outdated pandas version
import pandas as pd

data = pd.read_csv('data.csv', on_bad_lines=True)  # This line will throw the mentioned error

# To fix this, either update pandas or remove 'on_bad_lines' argument
# Option 1: Update pandas (recommended)
# Option 2: Remove 'on_bad_lines' argument
data = pd.read_csv('data.csv')
# Example 2: Removing 'on_bad_lines' argument
import pandas as pd

data = pd.read_csv('data.csv', on_bad_lines=True)  # This line will throw the error

# Remove 'on_bad_lines' argument
data = pd.read_csv('data.csv')

Similar post

Leave a comment