Error "KeyError: 'id'" on st.dataframe where style.format is used - sensitive to dataframe size

Issue using st.dataframe with df.styles.format to format floats with 2 decimal places. See gist containing minimal case with 2 files at:

ERROR occurs at line containing this statement:
st.dataframe(df.style.format({‘ItemSubTotalAmount’: ‘{:.2f}’, ‘TaxAmount’: ‘{:.2f}’, ‘TotalAmount’: ‘{:.2f}’}))

REPRODUCTION STEPS:

SUCCESS CASE:
streamlit run https://gist.github.com/evoshawkins/1432dc9dd3c6a4358c8eb28688519734/raw/5bc7998d663779150389973313c4a1396348ded2/issue.py

FAIL CASE:
streamlit run https://gist.github.com/evoshawkins/1432dc9dd3c6a4358c8eb28688519734/raw/5bc7998d663779150389973313c4a1396348ded2/issue-fail.py

The 1st example reads the CSV file from:
https://leg-2-lou-docs-pics.s3.us-west-2.amazonaws.com/reports/invoices_success_8456_rows.csv

The 2nd example points read the CSV file from: (it has one more row):
https://leg-2-lou-docs-pics.s3.us-west-2.amazonaws.com/reports/invoices_fail_8457_rows.csv

1 Like

+1

I also encounter this error attempting to display a large pandas styled dataframe.

With 58 columns (28 styled):

  • no error displaying 4519 rows or less
  • error displaying 4520 rows or more

+1
I have created a bug and shared a workaround for this. See KeyError: 'id' when using st.dataframe with pandas.Styler object and number of cells is higher than pandas `styler.render.max_elements` option · Issue #5953 · streamlit/streamlit · GitHub

1 Like

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