每个人都可以在X轴上看到,月份的顺序是随机的,但是我想按时间顺序排列月份,从1月到12月。谢谢你的回答
**#Counting the number of guests in both resort and city hotels**
Resort_Guests_Monhtly = Rh.groupby("arrival_date_month")["hotel"].count()
City_Guests_Monthly = Ch.groupby("arrival_date_month")["hotel"].count()
Resort_Guests_data = pd.DataFrame({"month":list(Resort_Guests_Monhtly.index),
"hotel":"Resort hotel",
"guests":list(Resort_Guests_Monhtly.values)})
City_Guests_data = pd.DataFrame({"month":list(City_Guests_Monthly.index),
"hotel":"City Hotel",
"guests":list(City_Guests_Monthly.values)}) function
**#Concenate the city and resort hotel data**
all_guests_data =pd.concat([Resort_Guests_data,City_Guests_data],ignore_index=True)
**#Trying to order the months but didn't work**
ordered_months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"]
all_guests_data['month'] = pd.Categorical(all_guests_data['month'], categories=ordered_months, ordered=True)
**#Visulization**
fig = px.line(all_guests_data, x="month" , y="guests",title="Average number of hotel guests per month", color='hotel')
fig.show()
如果我们着手解决x轴顺序,我们可以将此问题视为根据
ordered_months
列表对列month
上的数据帧all_guests_data
中的数据进行排序因此,我们在
**#Visulization**
之前添加以下两行澄清示例
相关问题 更多 >
编程相关推荐