资源简介
python数据分析基础教程附带源码
代码片段和文件信息
from matplotlib.finance import quotes_historical_yahoo
from datetime import date
import numpy as np
import matplotlib.pyplot as plt
from scipy import fftpack
from scipy import signal
from matplotlib.dates import DateFormatter DayLocator MonthLocator
from scipy import optimize
today = date.today()
start = (today.year - 1 today.month today.day)
quotes = quotes_historical_yahoo(“QQQ“ start today)
quotes = np.array(quotes)
dates = quotes.T[0]
qqq = quotes.T[4]
y = signal.detrend(qqq)
alldays = DayLocator()
months = MonthLocator()
month_formatter = DateFormatter(“%b %Y“)
fig = plt.figure()
ax = fig.add_subplot(211)
ax.xaxis.set_minor_locator(alldays)
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(month_formatter)
amps = np.abs(fftpack.fftshift(fftpack.rfft(y)))
amps[amps < amps.max()] = 0
def residuals(p y x):
Aktheta = p
err = y-A * np.sin(2* np.pi* k * x + theta)
return err
filtered = -fftpack.irfft(fftpack.ifftshift(amps))
N = len(qqq)
f = np.linspace(-N/2 N/2 N)
p0 = [filtered.max() f[amps.argmax()]/N np.pi/3]
plsq = optimize.leastsq(residuals p0 args=(filtered dates))
p = plsq[0]
print p
plt.plot(dates y ‘o‘ label=“detrended“)
plt.plot(dates filtered label=“filtered“)
plt.plot(dates p[0] * np.sin(2 * np.pi * dates * p[1] + p[2]) ‘^‘ label=“fit“)
fig.autofmt_xdate()
plt.legend()
ax2 = fig.add_subplot(212)
plt.plot(f amps label=“transformed“)
plt.legend()
plt.show()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 248 2013-02-11 23:19 Code\ch10code\a.mat
....... 1470 2013-02-11 22:51 Code\ch10code\algebra.py
....... 1390 2013-03-16 20:06 Code\ch10code\frequencies.py
....... 148 2013-02-11 22:56 Code\ch10code\gaussquad.py
....... 685 2013-03-16 22:38 Code\ch10code\images.py
....... 1711 2013-03-16 22:06 Code\ch10code\optfit.py
....... 851 2013-02-11 23:17 Code\ch10code\pair.py
....... 602 2011-07-27 22:46 Code\ch10code\README
....... 723 2013-02-12 18:11 Code\ch10code\repeat_audio.py
....... 93 2013-02-11 23:19 Code\ch10code\scipyio.py
....... 491 2013-02-11 23:22 Code\ch10code\sincinterp.py
....... 471 2013-02-11 23:23 Code\ch10code\statistics.py
....... 845 2013-03-16 19:31 Code\ch10code\trend.py
.....H. 12288 2013-02-15 12:14 Code\ch11code\.life_demo.py.swp
....... 901 2013-02-14 18:49 Code\ch11code\animation.py
....... 895 2013-02-14 21:09 Code\ch11code\clustering.py
....... 1302 2012-11-22 21:34 Code\ch11code\head.jpg
....... 2208 2013-02-15 12:14 Code\ch11code\life_demo.py
....... 1481 2013-02-14 19:10 Code\ch11code\matplotlib_demo.py
....... 978 2013-02-15 12:06 Code\ch11code\opengl_demo.py
....... 448 2012-11-18 22:47 Code\ch11code\simplegame.py
....... 574 2013-02-14 19:32 Code\ch11code\surfarray_demo.py
....... 555 2011-03-13 23:01 Code\ch1code\README
....... 1185 2013-01-12 22:34 Code\ch1code\vectorsum.py
....... 635 2013-01-16 19:16 Code\ch2code\arrayattributes.py
....... 2064 2013-01-16 19:30 Code\ch2code\arrayattributes2.py
....... 1312 2013-01-16 19:27 Code\ch2code\arrayconversion.py
....... 447 2013-01-16 19:58 Code\ch2code\charcodes.py
....... 392 2013-01-16 20:10 Code\ch2code\dtypeattributes.py
....... 387 2013-01-16 20:20 Code\ch2code\dtypeattributes2.py
............此处省略135个文件信息
- 上一篇:Python-rwda是一个微博数据分析的R包
- 下一篇:总年薪预测聚类分析.py
相关资源
- numpy-1.12.1rc1-cp27-none-win_amd64.whl
- numpy-1.11.2zip
- numpy-1.8.1-win32-superpack-python2.7
- Numpy1.8.1
- numpy-1.18.1-cp38-cp38-win32.whl
- python2.7 numpy安装
- numpy-1.13.1-cp27-none-win32.whl
- numpy-1.16.4.zip
- win7,64位,python3.5.2下的安装包:nu
- 《NumPy攻略:Python科学计算与数据分析
- Numpy for Python2.7 64bit
- numpy-MKL-1.8.1win-amd64
- numpy python3.7
- NumPy攻略:Python科学计算与数据分析
- python 2.7-64位_numpy+mkl
- numpy-1.18.1-cp37-cp37m-win_amd64.whl
- numpy-1.18.4+mkl-cp38-cp38-win_amd64.whl
- numpy-1.18.4+mkl-cp38-cp38-win_amd64.zip
- numpy-1.17.4-cp38-cp38-win_amd64.whl
- numpy-1.15.3-cp27-none-win_amd64.whl
- numpy-1.18.1-cp38-cp38-win_amd64.zip
- python数据分析之numpy-pandas-matplotlib-常
- numpy for python 2.7 (windows 64 bit)
- opencv_python-3.2.0-cp36-cp36m-win_amd64.whl
- numpy-amd64-py2.7.exe
- win64-python2.7.10+numpy+scipy+matplotlib+pyga
- numpy-1.14.0+mkl-cp36-cp36m-win_amd64.whl
- python2.7、numpy、matplotlib在windows 64位平
- Python3.4 Numpy安装包
- numpy-1.19.3+mkl-cp38-cp38-win_amd64.whl
评论
共有 条评论