[Python] Read and plot data from csv file

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Python] Read and plot data from csv file相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

python成绩

Python_报错:TypeError: file must have 'read' and 'readline' attributes

python plotly画柱状图

python plotly 画饼状图

python使用matplotlib可视化线图(line plot)设置X轴坐标的下限和上限数值(setting the lower and upper bound of the x axis)

python使用matplotlib可视化线图(line plot)设置Y轴坐标的下限和上限数值(setting the lower and upper bound of the y axis)