嗨,我有一个时间序列,我想计算我在数据帧中每分钟有多少事件 . 然后我想将所有日期组合在一起并使用事件打印日期时间 . 最后,我想使用bokeh和matplotlib输出折线图和直方图 .
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
#alows you to see matplotlib in Inotepad
%matplotlib inline
dframe = pd.read_table('info.txt', sep=",", header = None)
我正在将文本文件导入Juypter,数据帧称为dframe . 该行称为datetime . 我正在使用Juypter,pandas,numpy,bokeh或matplotlib
dframe
<id> <datetime>
0 20151227 06:51:30.218944
1 20151227 06:51:36.913871
2 20151227 06:51:37.198875
3 20151227 06:51:37.574203
4 20151227 06:51:37.286483
5 20151227 06:51:37.635841
6 20151227 06:51:38.070152
7 20151227 06:51:38.255787
8 20151227 06:51:38.188735
9 20151227 06:51:38.255831
10 20151227 06:51:38.255877
11 20151227 06:51:38.255920
12 20151227 06:51:38.893147
13 20151227 06:51:38.686167
正确输出的快速示例将如下所示,但由于以下错误,我无法打印输出 .
<datetime> event
20151227 06:51:30.218944 1
20151227 06:51:36.913871 2
20151227 06:51:37.198875 4
20151227 06:51:38.070152 8
当我重新采样数据时,我收到以下错误
dframe.datetime.resample('60Min', how=sum, base=30).plot()
plt.show()
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex
如何剥离秒,然后将所有“日期时间”组合在一起并使用事件打印日期时间然后在线图和组织图上绘制?
先感谢您
1 回答
为了完成这个,我刚刚使用SED删除了“ . ”之后的所有内容 . 然后我使用uniq进行分组和计数 . 删除秒后,我的折线图工作正常 .