Issue
I tried to drop value and plot the countplot but values are still there. What am I doing wrong?
df = df.drop(df[(df['market_segment'] == 'Undefined') & (df['market_segment'] == 'Aviation')].index)
plt.figure(figsize=(12,8))
sns.countplot(x='market_segment',data=df,hue='hotel')
plt.show()
Solution
There are 2 reasons this may be happening.
Your first line where you are filtering is incorrect
Your "market_segment" column may be a categorical dtype. In a categorical dtype Series, values that are not observed in the data can be propagated into
seaborn
, so converting to an object or string dtype can remedy this issue.
df = (
df.loc[~df["market_segment"].isin(["Undefined", "Aviation"])]
.astype({"market_segment": str})
)
plt.figure(figsize=(12,8))
sns.countplot(x='market_segment',data=df,hue='hotel')
plt.show()
Answered By - Cameron Riddell
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.