Pandas Dataframe每周对数据进行分组-Plotly库

时间:2020-06-09 01:01:26

标签: python pandas plotly plotly-python

我有一个看起来像这样的Pandas数据框-

ID |发布日期|主题

1 | 2020-03-11 |法律

2 | 2020-03-16 |房屋

3 | 2020-03-18 |房屋

4 | 2020-04-06 |法律

5 | 2020-04-08 |税收

Published Date是datetime64 [ns]列。

我想在绘图时间序列折线图中显示每个主题的每周出版量(按主题分组的每周出版物数)。 我不确定是否应该在使用Plotly之前对数据进行分组,或者Plotly具有可以帮助我完成此操作的功能。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

如果您将// Google login public function googleSocialLogin(Request $request){ Socialite::driver('google')->stateless()->redirect(); } // Google callback public function googleSocialLoginCallback(){ $userSocial = Socialite::driver('google')->stateless()->user(); $user = User::where('email',$userSocial->email)->first(); \Auth::login($user); return redirect()->intended($this->redirectPath()); } // Facebook login public function facebookSocialLogin(Request $request){ Socialite::driver('facebook')->stateless()->redirect(); } // Facebook callback public function facebookSocialLoginCallback(){ $userSocial = Socialite::driver('facebook')->stateless()->user(); $user = User::where('email',$userSocial->email)->first(); \Auth::login($user); return redirect()->intended($this->redirectPath()); } 列用作DateTime列,则可以执行以下操作:

Published Date

这将为您提供最终的DataFrame,以显示每个星期主题分组的大小(每组的行数)。

如果您的列不是DateTime格式,只需在列上使用# create new column with week-of-year value df['Week'] = df['Published Date'].dt.week # groupby week + topic (or vise-versa) gb = df.groupby(['Week', 'Topic'] volume = gb.size() 即可将其转换为(docs)