Problem with datatype of columns in a dataframe dislplayed with st.table()

In a dataframe I have column which stores int type list. While displaying it in normal way in my environment it is fine, the column is displayed like this:

[2007, 1270, 3264, 1412, 1046, 1628, 1170]
[1920, 786, 1129, 2847, 1592, 649]

but while displaying it in streamlit app using st.table(), st.dataframe() and st.write(), it is displaying like this

image

How to correct this?
Thanks

Hi @sachj28,

Have you tried using st.dataframe()?
I believe this should display the columns containing the lists correctly.

1 Like

same issue with st.write(), st.dataframe() and st.table()

Could you please share your code and source of the dataframe?

1 Like

The code:

extracted_data = {
    "player_id" : all_game_ids,
    'Tracker ID' : tracker_id_list,
    "Target Response Time(ms)" : player_response_stop,
    "No. of times obstacle appeared" : no_of_times_obstacle_appeared,
    "Explosion Response Times(ms)" : player_response_destroy,
    "Ammo preloaded?(1 = Yes)" : predloading_by_cycle,
    "Guess true?" : guessing_by_cycle,
    "No_of_times_ammo_preloaded"  : no_of_times_ammo_preloaded_4_each_cycle,
    "No_of_correct_guesses" : true_guessing_count,
    "Wall Response (distance)" : player_response_wall,
    "Time of Play (hr:min:s)" : cycle_start_time,
    "Distance b/w crosshair nd target" : distance_by_cycle,
    "Cycle Level" : cycle_level,
    "Total Score" : total_score,
    "cycle duration(in seconds)" : duration_of_each_cycle
}

df = pd.DataFrame(extracted_data)
df

dataframe:

1 Like

I see. Not sure if this is considered a bug or expected behaviour.
Possible work arrounds are:

  • convert columns with lists to str, just for display purposes; or
  • export dataframe as html
import random

import streamlit as st
import pandas as pd

data_size = 10

data = {
    "id_": list(range(data_size)),
    "data": [random.sample(range(10, 30), 5) for _ in range(data_size)]
}

df = pd.DataFrame(data)
df_converted = df.copy()
df_converted["data"] = df_converted["data"].astype(str)

st.subheader("Lists converted to str")
st.write(df_converted)

st.subheader("df converted to html")
st.write(df.to_html(), unsafe_allow_html=True)

1 Like

worked, thanks a lot

2 Likes