溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

對python pandas 畫移動平均線的方法詳解

發(fā)布時間:2020-09-16 04:58:18 來源:腳本之家 閱讀:396 作者:belldeep 欄目:開發(fā)技術(shù)

數(shù)據(jù)文件 66001_.txt 內(nèi)容格式:

date,jz0,jz1,jz2,jz3,jz4,jz5
2012-12-28,0.9326,0.8835,1.0289,1.0027,1.1067,1.0023
2012-12-31,0.9435,0.8945,1.0435,1.0031,1.1229,1.0027
2013-01-04,0.9403,0.8898,1.0385,1.0032,1.1183,1.0030
... ...

pd_roll_mean1.py

# -*- coding: utf-8 -*-
import os, sys
if len(sys.argv) ==2:
 i = sys.argv[1]
else:
 print 'usage: pd_roll_mean1.py i '
 sys.exit(1)
 
import pandas as pd
# dataFrame 第6章 數(shù)據(jù)加載 讀寫文本格式的數(shù)據(jù) 第167頁
df = pd.read_csv('/python/66001_.txt', parse_dates=True, index_col=0 )
 
df.head() # 預(yù)覽前5行數(shù)據(jù)
df.describe() # 數(shù)據(jù)基本統(tǒng)計量
 
import matplotlib.pyplot as plt
# 加這個兩句 可以顯示中文
plt.rcParams['font.sans-serif'] = [u'SimHei']
plt.rcParams['axes.unicode_minus'] = False
 
jz = 'jz'+str(i)
df[jz].plot(figsize=(12,6), grid=True, legend=jz, label='66001'+str(i)) 
# 畫30日移動平均線 
pd.rolling_mean(df[jz], 30).plot(grid=True)
plt.show()

運行 python pd_roll_mean1.py 5

參考書:[ 利用Python進(jìn)行數(shù)據(jù)分析 ]

以上這篇對python pandas 畫移動平均線的方法詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI