码迷,mamicode.com
首页 > 编程语言 > 详细

[Python] Read and plot data from csv file

时间:2017-12-15 21:37:43      阅读:415      评论:0      收藏:0      [点我收藏+]

标签:gpo   load   ica   otl   check   get   panda   pandas   lib   

Install:

pip install pandas
pip install matplotlib # check out the doc from site

 

import pandas as pd 
import matplotlib.pyplot as plt
from numpy import mean

def load_df(symbol):
    return pd.read_csv("data/{0}.csv".format(symbol))

def get_max_close(symbol):
    """ Return the maximum closing value for stock idicicated by symbol.
    Note: Data for a stock is stored in file: data/<symbol>.csv
    """
    df = load_df(symbol)
    return df["Close"].max()

def get_mean_volume(symbol):
    df = load_df(symbol)
    return mean(df[Volume])

def printAdjClose():
    df = pd.read_csv(data/ibm.csv)
    df[[Low, High]].plot()
    plt.show()

def test_run():
    """
    Function called by Test Run
    """
    for symbol in [aapl, ibm]:
        print("Max close")
        print(symbol, get_max_close(symbol))
        print("Mean Volume")
        print(symbol, get_mean_volume(symbol))

if __name__ == "__main__":
    test_run()
    printAdjClose()

 

[Python] Read and plot data from csv file

标签:gpo   load   ica   otl   check   get   panda   pandas   lib   

原文地址:http://www.cnblogs.com/Answer1215/p/8044819.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!