我有一个看起来像这样的文件
Times Code505 Code200 Code404
1543714067 855 86123 1840
1543714077 869 87327 1857
1543714087 882 88522 1883
1543714097 890 89764 1901
1543714107 904 90735 1924
1543714117 914 91963 1956
的图形
当我绘制图形时,我得到的更多信息
我正在做的第二张图是
data['Times'] = pd.to_datetime(data['Times'], unit = 's')
data.set_index(['Times'],inplace=True)
data.plot()
我知道我错过了一些东西来使我的图表看起来像一个时间序列,但是我不确定必须传递给熊猫什么才能使我的图表看起来正确。
我总共收集了一个小时的数据,并收集了一条类似这样的记录
1543714067 855 86123 1840
每10秒
答案 0 :(得分:2)
>>> df
Times Code505 Code200 Code404
0 1543714067 855 86123 1840
1 1543714077 869 87327 1857
2 1543714087 882 88522 1883
3 1543714097 890 89764 1901
4 1543714107 904 90735 1924
5 1543714117 914 91963 1956
>>>
这将基于二十秒的间隔来计算RPS:
向上移动数据上 2并减去原始DataFrame
>>> df.shift(-2)
Times Code505 Code200 Code404
0 1.543714e+09 882.0 88522.0 1883.0
1 1.543714e+09 890.0 89764.0 1901.0
2 1.543714e+09 904.0 90735.0 1924.0
3 1.543714e+09 914.0 91963.0 1956.0
4 NaN NaN NaN NaN
5 NaN NaN NaN NaN
>>>
>>> deltas = df.shift(-2) - df
>>> deltas
Times Code505 Code200 Code404
0 20.0 27.0 2399.0 43.0
1 20.0 21.0 2437.0 44.0
2 20.0 22.0 2213.0 41.0
3 20.0 24.0 2199.0 55.0
4 NaN NaN NaN NaN
5 NaN NaN NaN NaN
>>>
将三角洲除以20,然后重新建立时间。
>>> rates = deltas / 20
>>> rates
Times Code505 Code200 Code404
0 1.0 1.35 119.95 2.15
1 1.0 1.05 121.85 2.20
2 1.0 1.10 110.65 2.05
3 1.0 1.20 109.95 2.75
4 NaN NaN NaN NaN
5 NaN NaN NaN NaN
>>> rates['Times'] = df['Times']
>>> rates
Times Code505 Code200 Code404
0 1543714067 1.35 119.95 2.15
1 1543714077 1.05 121.85 2.20
2 1543714087 1.10 110.65 2.05
3 1543714097 1.20 109.95 2.75
4 1543714107 NaN NaN NaN
5 1543714117 NaN NaN NaN
>>>
如果首先将其作为索引,则可以保留整个过程中的时间戳。
>>> df
Times Code505 Code200 Code404
0 1543714067 855 86123 1840
1 1543714077 869 87327 1857
2 1543714087 882 88522 1883
3 1543714097 890 89764 1901
4 1543714107 904 90735 1924
5 1543714117 914 91963 1956
>>> df = df.set_index('Times')
>>> df
Code505 Code200 Code404
Times
1543714067 855 86123 1840
1543714077 869 87327 1857
1543714087 882 88522 1883
1543714097 890 89764 1901
1543714107 904 90735 1924
1543714117 914 91963 1956
>>>
>>> deltas = df.shift(-2) - df
>>> rates = deltas / 20
>>> rates
Code505 Code200 Code404
Times
1543714067 1.35 119.95 2.15
1543714077 1.05 121.85 2.20
1543714087 1.10 110.65 2.05
1543714097 1.20 109.95 2.75
1543714107 NaN NaN NaN
1543714117 NaN NaN NaN
>>>