. Advertisement .
. Advertisement .
If you have the “dropna() got an unexpected keyword argument ‘thresh’” error of data cleaning in Python which means solving bad data in the data set. The Bad data could be empty cells; data in wrong format; wrong data; and duplicates. In this case, we will solve the effective solution to settle the error which is one of the causes of the bad data. Don’t miss this article to explore the method to correct it!
When does the “dropna() got an unexpected keyword argument ‘thresh’” error occur?
You have a column names list and would like to remove the rows which have the value of more than one
NaN. So, you got the following error:
dropna() got an unexpected keyword argument 'thresh'
I believe that you check the function of pandas whether it is updated or not and the version of panda could be 1.1.5. You have done the data cleaning and it is able to originate the df rows became
str. Below is the code that you converted to the
np.nan as follow:
df = pd.read_csv('dataframe.csv', index=False) col_list = ['col1', 'col2', 'col3'] """ # DataClean for col in col_list: df[col] = pd.to_numeric(df[col] .str.replace('[^0-9- ]', '') .str.split(' - ') .explode() ).mean(level=0) """ df = df.replace('NaN', np.nan) for col in col_list: df[col] = df[col].dropna(thresh=1, axis=0)
To fix the “dropna() got an unexpected keyword argument ‘thresh’” error
Use dropna(thresh=1, axis=0)
Before solving the “dropna() got an unexpected keyword argument ‘thresh’” error, the first step you need to do is seeing your purpose for this command. You only want to find the NaN values, so you should use the right code to search for them.
Let’s use the dropna(thresh=1, axis=0) in the block, it will remove rows with
NaN values. For your intention, you can execute the following command:
df.dropna(subset=col_list, how='any', axis=0)
We have experienced the above method and find that it is the most effective solution for fixing “dropna() got an unexpected keyword argument ‘thresh’” error. It gave us amazing result, and the error completely disappeared. Let’s do it to get your desired result.
We have shared the effective solution to fix the “dropna() got an unexpected keyword argument ‘thresh’” issue and take a note for the coming problem in the future. Hope the above solutions will be useful to you. Thank you for following our article and don’t miss to leave a comment for us if you need assistance or have any questions. In addition, we still have many other articles on related content in the process of using Python, please refer to it! Wish you a surprising day with the programming!