绘制大熊猫系列数据的平滑曲线

问题描述 投票:4回答:3

我的数据是:

>>> ts = pd.TimeSeries(data,indexconv)
>>> tsgroup = ts.resample('t',how='sum')
>>> tsgroup
2014-11-08 10:30:00    3
2014-11-08 10:31:00    4
2014-11-08 10:32:00    7
  [snip]
2014-11-08 10:54:00    5
2014-11-08 10:55:00    2
Freq: T, dtype: int64
>>> tsgroup.plot()
>>> plt.show()

indexconv是使用datetime.strptime串转换。

情节是这样很尖锐(这些都不是我的实际图):

我怎样才能顺利出来是这样的:

我知道在scipy.interpolate提到的(这是我从图片)this article,但我该如何应用它的熊猫时间序列?

我发现这个所谓的Vincent与熊猫涉及大图书馆,但它不支持的Python 2.6。

python pandas plot interpolation
3个回答
5
投票

得到它了。从this question的帮助,这是我做的:

  1. 从分钟重新取样我tsgroup到秒。 \ >>> TSRES = tsgroup.resample( 'S')\ >>> TSRES 2014年11月8日10点三十零分00秒3 2014年11月8日十点30分01秒的NaN 2014年11月8日10:30: 02 NaN的2014年11月8日10时30分03秒的NaN ...... 2014年11月8日10时54分58秒的NaN 2014年11月8日10时54分59秒的NaN 2014年11月8日10:55:00 2频率:S,长度:1501
  2. 使用.interpolate(method='cubic')插值数据。这将数据传递给scipy.interpolate.interp1d并使用cubic样,所以你需要有SciPy的安装(pip install scipy)1。 \ >>> TSINT = tsres.interpolate(方法= '立方')\ >>> TSINT 2014年11月8日10时30分○○秒3.000000 2014年11月8日10时三十分01秒3.043445 2014年11月8日10: 30:02 3.085850 2014年11月8日10时30分03秒3.127220 ...... 2014年11月8日十时54分58秒2.461532 2014年11月8日10点54分59秒2.235186 2014年11月8日10:55:00 2.000000频率:S,长度:1501
  3. 使用tsint.plot()绘制。这里是原来的tsgrouptsint之间的比较:

1如果您收到来自.interpolate(method='cubic')一个错误,告诉你,即使你都安装了SciPy的没有安装,打开/usr/lib64/python2.6/site-packages/scipy/interpolate/polyint.py或任何你的文件可能是从from scipy import factorial更改第二行from scipy.misc import factorial


1
投票

你可以用均线为好,有效地施加了低通滤波器,将数据平滑数据。大熊猫支持这一与rolling()方法。


© www.soinside.com 2019 - 2024. All rights reserved.