So I have this function that I made using the outlier formula.
def remove_outlier_IQR(df):
q1 = df.quantile(0.25)
q3 = df.quantile(0.75)
inter_q = q3-q1
df_final = ~((df<(q1 - 1.5*inter_q)) | (df>(q3 + 1.5*inter_q))).any(axis=1)
df_final = pd.DataFrame(df_final)
return df_final
The two columns that I want the outlier removed looked somewhat like this.
df[["Umur","Skor Belanja (1-100)"]]
Below is the outlier presented in the boxplot I used to check.

This is the second boxplot that I use to check.

Now I use the outlier function to remove the outlier presented.
df_outlier_removed = remove_outlier_IQR(df[["Umur","Skor Belanja (1-100)"]])
df_outlier_removed.dropna(axis = 0, inplace =True)
After that, I checked again this time using the df_outlier_removed data frame into a boxplot
sns.boxplot(x = "Umur",data=df_outlier_removed)
It returns this error.
ValueError: Could not interpret input 'Umur'
I think to myself that it is weird as to why this is happening. So I checked the df_outlier_removed function to check its value and I got this.
df_outlier_removed
No wonder the boxplot did not read it because the value is in boolean.
I changed the return value to an integer so that it did not return a boolean but instead an integer on the remove_outlier_IQR data frame.
def remove_outlier_IQR(df):
q1 = df.quantile(0.25)
q3 = df.quantile(0.75)
inter_q = q3-q1
df_final = ~((df<(q1 - 1.5*inter_q)) | (df>(q3 + 1.5*inter_q))).any(axis=1)
df_final.astype('int')
df_final = pd.DataFrame(df_final)
return df_final
So I ran the boxplot to check for the outlier
sns.boxplot(x = "Umur",data=df_outlier_removed)
It still return the error code for
ValueError: Could not interpret input 'Umur'
What should I do?

