我有一个像这样的 Julia DataFrame:
? Row ? date ? users ? posts ? topics ? likes ? pageviews ?
? ? Date ? Int64 ? Int64 ? Int64 ? Int64 ? Int64 ?
??????????????????????????????????????????????????????????????????????????
? 1 ? Date("2020-06-16") ? 1 ? 3 ? 4 ? 7 ? 10000 ?
? 2 ? Date("2020-06-15") ? 2 ? 2 ? 5 ? 8 ? 20000 ?
? 3 ? Date("2020-06-14") ? 3 ? 3 ? 6 ? 9 ? 30000 ?
Run Code Online (Sandbox Code Playgroud)
我想要一个帖子与日期的图,但每日数据太嘈杂,所以我想对每周的帖子求和并绘制它?实现这一目标的最简单方法是什么。
TimeSeries 包提供了各种实用程序来处理 TimeSeries 数据。\n在这种情况下,您可以使用 将collapse
每日数据转换为每周数据:
julia> using TimeSeries, DataFrames\n\njulia> ta = TimeArray(df.date, df.posts)\n1311\xc3\x971 TimeArray{Int64,1,Date,Array{Int64,1}} 2016-10-19 to 2020-06-16\n\xe2\x94\x82 \xe2\x94\x82 A \xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xa4\n\xe2\x94\x82 2016-10-19 \xe2\x94\x82 1 \xe2\x94\x82\n\xe2\x94\x82 2016-10-20 \xe2\x94\x82 2 \xe2\x94\x82\n\xe2\x94\x82 2016-10-21 \xe2\x94\x82 3 \xe2\x94\x82\n\xe2\x94\x82 2016-10-23 \xe2\x94\x82 4 \xe2\x94\x82\n...\n\njulia> weekly = collapse(ta, week, last, sum)\n192\xc3\x971 TimeArray{Int64,1,Date,Array{Int64,1}} 2016-10-23 to 2020-06-16\n\xe2\x94\x82 \xe2\x94\x82 A \xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xa4\n\xe2\x94\x82 2016-10-23 \xe2\x94\x82 10 \xe2\x94\x82\n\xe2\x94\x82 2016-10-28 \xe2\x94\x82 22 \xe2\x94\x82\n\xe2\x94\x82 2016-11-06 \xe2\x94\x82 34 \xe2\x94\x82\n...\n\njulia> using Gadfly\njulia> plot(DataFrame(weekly)[1:end-1,:], x=:timestamp, y=:A, Geom.line(), Guide.ylabel("Weekly sum of Posts"), Guide.xlabel("Week"))\n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
212 次 |
最近记录: |