Search code examples
pythonmplfinance

mplfinance error,Data for column "Open" must be ALL float or int


the code works three days ago

#!pip install mplfinance
import pandas as pd
import yfinance as yf
import mplfinance as mpf

# get data
symbol = "AAPL"
start_date = "2022-01-01"
end_date = "2022-12-31"
stock_data = yf.download(symbol, start=start_date, end=end_date)

# index
stock_data.index = pd.to_datetime(stock_data.index)

# K_line
mpf.plot(stock_data, type='candle', style='yahoo', title=f'{symbol} ')

I convert the type to float or int, but it still don't work,

pic


Solution

  • I had the same problem Code:

    stock_data = yf.download(symbol, start=start_date, end=end_date)
    

    Change to:

    aapl = yf.Ticker(symbol)
    stock_data = aapl.history(start=start_date, end=end_date)
    

    I don't know why but it works for me.