This issue is solved in
randyzwitch
is right but instead of using st.write you need to use st.text, other way will display an ugly str.
solution by: snehankekre
buffer = io.StringIO()
df.info(buf=buffer)
s = buffer.getvalue()
st.text(s)
Alternatively, if you want the output as da data frame for whatever reasons you can use this code:
def get_df_info(df):
buffer = io.StringIO ()
df.info (buf=buffer)
lines = buffer.getvalue ().split ('\n')
# lines to print directly
lines_to_print = [0, 1, 2, -2, -3]
for i in lines_to_print:
st.write (lines [i])
# lines to arrange in a df
list_of_list = []
for x in lines [5:-3]:
list = x.split ()
list_of_list.append (list)
info_df = pd.DataFrame (list_of_list, columns=['index', 'Column', 'Non-null-Count', 'null', 'Dtype'])
info_df.drop (columns=['index', 'null'], axis=1, inplace=True)
st.dataframe(info_df)