Search code examples
pythonmatplotlibquantitative-finance

Matplotlib candlestick TypeError: unsupported operand type(s) for -: 'str' and 'str'


I have a Dataframe in the format as follows:

    Date    Open    Close    High    Low    Volume
1   float   float   float    float   float  int64
2   ...
3   ...

The Date is in float days format and everything else (except Volume) is a float as confirmed by df.types.

I passed this Dataframe to a matplotlib .candlestick_ochl() method, as follows:

import matplotlib.finance as mf

mf.candlestick_ochl(ax, df)

The return is TypeError: unsupported operand type(s) for -: 'str' and 'str' which makes me feel like I'm somehow getting an error that candlestick_ochl() is trying to subtract two strings, but where?

In the traceback
the error arises from line 788 in finance.py _candlestick: height = close - open

Thanks for any advice!


Solution

  • per tcaswell's note I simply added the following changes:

    MOCHLV = zip(df.Date, df.Open, df.Close, df.High, df.Low, df.Volume)
    
    mf.candestick_ochl(ax, MOCHLV)