Read_excel() got an unexpected keyword argument ‘encoding’

Explanation:

The error message “read_excel() got an unexpected keyword argument ‘encoding'” indicates that the Pandas function ‘read_excel()’ does not have an argument called ‘encoding’, but it was used as a keyword argument.

The ‘encoding’ argument in Pandas’ ‘read_excel()’ function is used to specify the encoding type of the Excel file being read. However, the error suggests that the function does not recognize ‘encoding’ as a valid argument.

Example:

To demonstrate this error, consider the following example:

    
import pandas as pd
df = pd.read_excel('data.xlsx', encoding='utf-8')
    
  

In this example, ‘data.xlsx’ is the Excel file that we are trying to read. The ‘encoding’ argument is set to ‘utf-8’, but Pandas throws the error because it does not recognize ‘encoding’ as a valid keyword argument for ‘read_excel()’.

Solution:

To resolve this error, we need to remove the ‘encoding’ argument from the ‘read_excel()’ function because it is not supported. By default, Pandas uses the system’s default encoding for reading Excel files. So, the correct usage would be:

    
import pandas as pd
df = pd.read_excel('data.xlsx')
    
  

In this updated example, ‘data.xlsx’ is being read without specifying the ‘encoding’ argument. This will use the default encoding and resolve the error.

Read more interesting post

Leave a comment