Javascript error on using st.table() to display a data frame built using pandas.cut() function

Hi,

On trying to create a Frequency Distribution table I am able to get the desired output in the terminal, but I get a Javascript error while trying to render the table in the Streamlit UI.

I am a little confused because it does not look like a Python error.

Here is the code I used -

mrr_df = filtered_df_current_month['mrr']
mrr_bin = pd.cut(mrr_df,10).to_frame()
st.table(mrr_bin.value_counts())

Hi @mjo, welcome to the community! :wave: :partying_face:

Could you provide a minimal reproducible code example? Also, what version of Streamlit are you using? The below snippet works without errors on Streamlit v1.11.0:

import numpy as np
import pandas as pd
import streamlit as st

st.table(pd.cut([0, 1, 1, 2], bins=4, labels=False))

Best, :balloon:
Snehan

Hi @snehankekre,

Thanks for taking out the time to reply.

Here is the code you requested -

metric = Series([24, 67,36,489,28,389,390])
metric_df = pd.cut(metric,2).to_frame()
st.table(metric_df.value_counts())

This is the error -

When I just try to print in the terminal, instead of using st.table(), I get a proper output. Here is the code -

metric = Series([24, 67,36,489,28,389,390])
metric_df = pd.cut(metric,2).to_frame()
print(metric_df.value_counts())

Here is the output -
image

I am using Streamlit v1.11.0

I hope this helps. Thanks for your help.
mjo

Hi @mjo :wave:

Unfortunately, this looks like a bug! :bug: I would suggest submitting a new issue / bug report.

Thanks @snehankekre . I have already created an issue.

Linking here for convenience sake. Getting a Javascript error on trying to display a table using st.table(). · Issue #5027 · streamlit/streamlit · GitHub

I think someone will look at this later this week @mjo . Thanks for submitting your issue!

Hey @mjo, I started to investigate this issue. I get a different error with the linked snippet:

metric = Series([24, 67,36,489,28,389,390])
metric_df = pd.cut(metric,2).to_frame()
st.table(metric_df.value_counts())

However, if I remove the .value_counts() I get the mentioned TypeError. Maybe there are even two distinct errors.

Hey @lukasmasuch ,

Streamlit is not behaving consistently in this regard. The first time I executed the code, I got the error you have shown above in the app and the terminal. However, when I re-execute the same code, I continue to get this error (StreamlitAPIException) in the terminal. But in the app itself, I am getting the TypeError.

But I agree that it looks like there are two different errors.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.