Storing stock quotes data from this object into python panda data frame

I have a python object imported from win2com which contains stock price quotations. numbars is the number of bars in the stock history. quotations is the object that contain the stock quotations.

To retrieve and store the prices and dates, the python code will look something like this;

for x in range(0,num_bars):
    date_quote[x] = quotations(x).Date.date()
    close[x] = quotations(x).Close
    open[x] = quotations(x).Open
    high[x] = quotations(x).Low
    low[x] = quotations(x).High
    volume[x] = quotations(x).Volume
    open_int[x] = quotations(x).OpenInt

I just discovered panda dataframe today and thought it will be better to store the stock quotations data into panda dataframe to make use of the ecosystem built around panda. However, when I looked at the dataframe structure created by pandas_datareader module, it looked highly complicated. Are there any convenient way, like an API or library, to store the stock data from quotations object into panda data frame?

I am using python v3.6


You can do following:

import pandas as pd

df = pd.DataFrame(columns=['Date', 'Close', 'Open', 'Low', 
                           'High', 'Volume', 'OpenInt'])
for i in range(num_bars):
    df.loc[i] = [quotations(i).Date.date(),
                 quotations(i).Close,
                 quotations(i).Open,
                 quotations(i).Low,
                 quotations(i).High,
                 quotations(i).Volume,
                 quotations(i).OpenInt]

After that, you'l have df DataFrame with stock quotations data.


Maybe you are looking for:

from pandas_datareader import data aapl = data.DataReader('AAPL', 'google', '1980-01-01')

链接地址: http://www.djcxy.com/p/38410.html

上一篇: 我应该瞄准哪种版本的OpenGL / Direct3D以获得最佳兼容性?

下一篇: 将此对象的股票报价数据存储到python熊猫数据框中