使用情节计算每月平均价格和情节
我有一个数据框架,该数据框架在2021年10月至今天的每日时间内都包含两个地区的售价。
我想找到每月的平均房价,并使用Plotly绘制图表,以查看每个区域的价格是否下跌或上涨。
示例dataframe:
DateSold Price Area
12/10/2021 00:00 300000 Area A
17/10/2021 00:00 350000 Area B
18/10/2021 00:00 400000 Area B
11/12/2021 00:00 412000 Area A
17/12/2021 00:00 315000 Area A
08/01/2022 00:00 385000 Area A
09/01/2022 00:00 445000 Area A
15/01/2022 00:00 309000 Area B
15/01/2022 00:00 350000 Area B
我试图按月频率将dateTime列转换为周期索引,然后使用groupby.mean:emean:
df2.groupby(pd.PeriodIndex(df2['Datesold'], freq="M"))['Price'].mean()
有人可以指向我如何达到我如何达到平均房价的正确方向每月并使用情节绘制?
我正在使用以下代码进行绘图
fig = px.line(df, x = df['DateSold'], y = df['Price'], title='Average sold house price
I have a Dataframe which contains sold house prices in two areas over a daily period from Oct 2021 till today.
I want to find the average house price per month and plot a graph using plotly to see if prices are going down or up in each area.
Sample DataFrame:
DateSold Price Area
12/10/2021 00:00 300000 Area A
17/10/2021 00:00 350000 Area B
18/10/2021 00:00 400000 Area B
11/12/2021 00:00 412000 Area A
17/12/2021 00:00 315000 Area A
08/01/2022 00:00 385000 Area A
09/01/2022 00:00 445000 Area A
15/01/2022 00:00 309000 Area B
15/01/2022 00:00 350000 Area B
I tried to convert the datetime column into a PeriodIndex on monthly frequency, then take the mean using GroupBy.mean:
df2.groupby(pd.PeriodIndex(df2['Datesold'], freq="M"))['Price'].mean()
Can someone point me in the right direction in how I can achieve the average house price per month and plot that using plotly?
I was using the below code for plotly
fig = px.line(df, x = df['DateSold'], y = df['Price'], title='Average sold house price
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的DateTime列没有频率或周期性。即使是这种情况,您也无需转换为
ofientIndex
。您可以使用datesold
列的月份/月_名称进行分组,如下所示:然后,您可以用plotly绘制结果
Your DateTime column does not have a frequency or periodicity. Even if it were the case, you wouldn't need to convert to
PeriodIndex
. You can group by using the month/month_name of theDateSold
column as follows:You can then plot the result with plotly