What is the difference between st.dataframe(df) vs st.write(df)

Hello,

The output looks the identical. But when would you use one over the other?

TIA!

Hi Jeisma
In my opinion st.write() is a combination of output function, it output based on what you put in, for example you can use st.write(df), st.write(error) or even st.write(altair_chart). For me the best thing about st.write() is it can output multiple item, such as st.write(df, df[β€˜col1’].dtype, fig1) in 1 line.

1 Like

You are correct @oliverjia…st.write inspects the class of the object, then tries to do what we think the user intent is. So it will go through a hierarchy of the other methods like st.json, st.dataframe, st.table, st.markdown etc.

So the easy heuristic is, you can use st.write until it doesn’t do what you want, then be more specific if you want control over the output and a specific function has other arguments you want to pass.

Best,
Randy

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