Numpy Array missing dates when I get data from an api (yfinance)

Viewed 444

I am trying to gather stock data on an Numpy Array in which the dates of the stock prices are in the first column. When I turn the data directly into an array I will get [ 30.99 32.08 32.12 ... 318.66 315.77 323.5 ] here is my code below.

import numpy as np
import yfinance as yf

def price(ticker):
    company = yf.Ticker(ticker)
    price = company.history(period="10y")
    array = np.array(price)
    return array
aapl = price("AAPL")
Aaple = aapl[:, 0]

If I use a dataframe I will get this

def price(ticker):
    company = yf.Ticker(ticker)
    price = company.history(period="10y")
    df = pd.DataFrame(price)
    df.drop(df.columns[i], axis=1)
    return df
aapl = price("AAPL")
print(aapl)


                  Open    High     Low   Close     Volume  Dividends  Stock Splits
Date                                                                          
2010-05-27   30.99   31.40   30.81   31.33  166570600       0.00           0.0
2010-05-28   32.08   32.08   31.33   31.77  203903700       0.00           0.0
...            ...     ...     ...     ...        ...        ...           ...

2020-05-22  315.77  319.23  315.35  318.89   20450800       0.00           0.0
2020-05-26  323.50  324.20  316.50  316.73   30880340       0.00           0.0

I can reset the dataframes index df.reset_index() and be able to access the dates. How come I cannot access dates in the array, what is the fix? I do not want to use dataframes since arrays are much faster.

1 Answers
Related