I have this code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
sns.set_style('darkgrid')
sns.set_theme()
df = pd.read_csv("https://raw.githubusercontent.com/lokalhangatt/stackoverlow/refs/heads/main/airbnb_nyc_2019.csv")
df.fillna({'reviews_per_month':0}, inplace=True) #inplace=True
I want to show that for each room_type
, the price
in Manhattan is the highest compared to other neighborhood_group
. If I wrangle the data with this code:
df[['neighbourhood_group', 'room_type', 'price']].value_counts('neighbourhood_group')
>> out[]:
neighbourhood_group
Manhattan 21661
Brooklyn 20104
Queens 5666
Bronx 1091
Staten Island 373
Name: count, dtype: int64
df.groupby(['room_type', 'neighbourhood_group'])['price'].size()
>>> out[]:
room_type neighbourhood_group
Entire home/apt Bronx 379
Brooklyn 9559
Manhattan 13199
Queens 2096
Staten Island 176
Private room Bronx 652
Brooklyn 10132
Manhattan 7982
Queens 3372
Staten Island 188
Shared room Bronx 60
Brooklyn 413
Manhattan 480
Queens 198
Staten Island 9
Name: price, dtype: int64
If I plot the data with this code:
sns.catplot(data=df,
kind='strip',
x='neighbourhood_group',
y='price',
col="room_type",
hue="neighbourhood_group",
col_wrap=3,
palette="deep",
order=sorted(df.neighbourhood_group.unique()),
col_order=sorted(df.room_type.unique()),
sharex=False
)
plt.show()
But if I change to kind='bar'
, it’ll show something like this:
I am just confused about why it shows the difference in price result in the y-axis. And if I want to use the barplot, is it possible to adjust the y-axis to the real price as shown in the code above?
You need to sign in to view this answers
Leave feedback about this