question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(df.index)): TypeError: '>' not supported between instances of 'str' and 'float'

See original GitHub issue

Hi Jonas, Thanks for this wonderful gem of a library 😃 HERE is a comment from you a while back. Now I’m trying to plot data from a json object.

THIS Is the API endpoint.

When I try below code based on your advice (I’m nearly certain I’m doing it wrong),

import requests as rq
import pandas as pd
import finplot as fplt


url = 'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=IBM&interval=5min&apikey=demo'

r = rq.get(url).json()

ax = fplt.create_plot('test', rows=1)

# plot candle sticks
fplt.candlestick_ochl(r['Time Series (5min)'], ax=ax)

I’m met with this traceback,

Traceback (most recent call last):
  File "C:\BeingProfessional\projects\Py\SoFlow.py", line 22, in <module>
    fplt.candlestick_ochl(r['Time Series (5min)'], ax=ax)
  File "C:\Program Files\Python37-32\lib\site-packages\finplot\__init__.py", line 1254, in candlestick_ochl
    datasrc = _create_datasrc(ax, datasrc)
  File "C:\Program Files\Python37-32\lib\site-packages\finplot\__init__.py", line 1819, in _create_datasrc
    datasrc = do_create(*args)
  File "C:\Program Files\Python37-32\lib\site-packages\finplot\__init__.py", line 1818, in do_create
    return PandasDataSource(pd.concat(args, axis=1))
  File "C:\Program Files\Python37-32\lib\site-packages\finplot\__init__.py", line 160, in __init__
    if type(df.index) == pd.DatetimeIndex or df.index[-1]>1e7 or '.RangeIndex' not in str(type(df.index)):
TypeError: '>' not supported between instances of 'str' and 'float'

My queries are,

  1. How do I plot this json response data in finplot? If it makes it easier, I am okay with a solution with pandas.
  2. Why does finplot throw this error?
  3. If there is something wrong with this json formatting, how about the TD Ameritrade API’s price history json? I know how to use TDA API, but how do I plot that data in finplot? The json schema looks like THIS

I’ll appreciate any help or suggestion…

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
highfestivacommented, Nov 19, 2020

Btw. this is what you need to do to get your first example plotting:

url = 'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=IBM&interval=5min&apikey=demo'
r = rq.get(url).json()
ts = r['Time Series (5min)']
rows = [[t]+list(kv.values()) for t,kv in ts.items()]
df = pd.DataFrame(data=rows, columns=['timestamp']+list(next(iter(ts.values()))))
df = df.rename(columns={'1. open':'open', '2. high':'high', '3. low':'low', '4. close':'close', '5. volume':'volume'})
df['timestamp'] = pd.to_datetime(df['timestamp'])
df = df.set_index('timestamp')
df = df.astype(float)

Note though, that the open and close columns are actually inversed in the downloaded data! We fix by simply flipping open and close when plotting like so:

fplt.candlestick_ochl(df[['close','open','high','low']]) # close before open
fplt.show()
1reaction
highfestivacommented, Nov 19, 2020

… regarding your first example/bug you need some more data processing, but out of the scope for a plotting library:

  1. Put each timestamp per row.
  2. Make it into a matrix.
  3. Convert all values from strings to their respective types (datetime and floats).

Then you can plot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: '>' not supported between instances of 'float' and ...
This is due to the series df[cat] containing elements that have varying data types e.g.(strings and/or floats). This could be due to the...
Read more >
Getting "TypeError: '>' not supported between instances of 'str ...
It is due to the missing values in the columns gender,married and dependents. use df.count() to check which columns have missing values and...
Read more >
' not supported between instances of 'str' and 'int' - Java2Blog
In this article you will learn about the causes and solutions of - TypeError: '<' not supported between instances of 'str' and 'int'...
Read more >
BUG: TypeError: '<' not supported between instances of 'float ...
I use df. combine_first(...) to add a column to a dataframe while extending the index in case an index value does not exist...
Read more >
Solve typeerror not supported between instances of str and int ...
As mentioned above, the root cause is that the variable instances of string and integer type are not compatible and hence can't be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found