[Python] Python yfinance: Difference between two methods of getting historical data with...

Discussão em 'Python' iniciado por Stack, Fevereiro 15, 2025.

  1. Stack

    Stack Membro Participativo

    Hello everyone and good night!

    I'm collecting data in two different ways for a hobby application:

    data = yf.Ticker(ticker).history(start=bonus_date, end=end_date)
    data2 = (yf.download([ticker], start=bonus_date, end=end_date, actions=True))[['Open', 'High', 'Low', 'Close', 'Volume', 'Dividends', 'Stock Splits']]
    data = data.reset_index()
    data2 = data2.reset_index()

    if isinstance(data2.columns, pd.MultiIndex):
    data2.columns = data2.columns.droplevel(1)

    print(data2.columns)
    print(data.columns)

    data.to_csv("output1.csv", index=False)
    data2.to_csv("output2.csv", index=False)


    The two csv outputs are equal, but when I use "data" variable in my final application, everything works fine. When I use data2 variable in my final application, I receive an error:


    raise IndexError("single positional indexer is out-of-bounds") IndexError: single positional indexer is out-of-bounds 127.0.0.1 - - [14/Feb/2025 22:53:58] "POST / HTTP/1.1" 500 -
    ​

    Looks like the "Date" columns is not beign recognized as Index of my dataframe, but I'm not sure what I can do to correct that. Could you please assist me on that?

    Obs: I really want to use the "data2" information because I don't want to use adjusted values at the yfinance lib.

    Thank you very much in advance!

    Continue reading...

Compartilhe esta Página