時以前,我是問到get week numbers on multiple year that is ready for plotting,並根據jezrael的答案,我這樣做:不支持的操作數類型(S) - :「海峽」和「浮動」建設條形圖
sheet2['device_create_week'] = sheet2['device_create_at'].dt.strftime('%Y-%V')
sheet2.groupby(['device_create_week']).size().reset_index(name='device created count weekly')
然後,我移動到繪圖
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams['figure.figsize'] = (10, 6)
rcParams['figure.dpi'] = 150
fig = plt.figure()
plt.bar(pre['user_create_week'],pre['user created count weekly'], align='center', alpha=0.5)
plt.xlabel('week')
plt.ylabel('frequency')
plt.show()
fig.savefig('test.jpg')
然後我看到一個錯誤:
TypeError: unsupported operand type(s) for -: 'str' and 'float'
那我該怎麼辦?我有預期的解決方案,可以繪製頻率爲每週的條形圖。
如果你想要的數據去嘗試,這是我的數據,你可以嘗試:
136 2014-08-27 10:19:46
245 2014-09-25 09:13:22
257 2014-09-29 15:22:16
258 2014-09-29 15:22:16
480 2015-02-02 10:01:25
481 2015-02-02 10:01:25
482 2015-02-02 10:01:25
483 2015-02-02 10:01:25
484 2015-02-02 10:01:25
485 2015-02-02 10:01:25
486 2015-02-02 10:01:25
487 2015-02-02 10:01:25
488 2015-02-02 10:01:25
536 2015-02-09 08:00:29
589 2015-02-02 10:01:25
590 2015-02-02 10:01:25
591 2015-02-02 10:01:25
592 2015-02-02 10:01:25
593 2015-02-02 10:01:25
594 2015-02-02 10:01:25
595 2015-02-02 10:01:25
596 2015-02-02 10:01:25
597 2015-02-02 10:01:25
694 2015-02-27 16:02:23
1573 2015-04-20 16:44:20
1574 2015-04-20 16:44:20
1779 2015-04-27 03:06:09
2119 2015-05-07 06:32:38
2120 2015-05-07 06:32:38
2306 2015-05-13 03:29:19
89876 2017-10-04 06:20:09
89933 2017-10-06 11:04:38
89943 2017-10-06 12:12:58
89947 2017-10-06 12:50:30
89952 2017-05-22 12:47:37
89957 2017-10-06 14:37:23
89958 2017-10-06 14:38:43
89984 2017-10-06 18:41:46
90022 2017-10-07 01:19:39
90053 2017-10-07 01:48:46
90117 2017-10-03 05:36:33
90122 2017-10-07 06:52:07
90129 2017-08-21 14:59:27
90145 2017-10-07 11:04:50
90157 2017-10-07 11:51:09
90164 2017-10-07 12:08:38
90202 2017-10-08 01:01:45
90216 2017-10-08 03:12:07
90222 2017-10-08 04:41:01
90228 2017-10-08 05:27:24
90238 2017-10-08 06:22:46
90250 2017-10-08 07:10:12
90266 2017-10-08 09:01:40
90276 2017-10-08 10:15:59
90291 2017-10-08 11:47:35
90294 2017-10-08 11:50:42
90298 2017-08-29 04:21:27
90313 2017-10-08 16:01:15
90363 2016-11-26 13:00:18
這也適用於我的筆記本以及任何想法使空的星期也顯示? –
以及如何讓酒吧之間沒有空間? –
第二個問題很簡單 - 在'plot'中使用參數'width = 1.0'。 – jezrael