Datetimeindex format

Hello there, community:

I’m using Streamlit for my Python Data Science Web Projects. So far, so good.

But, why I get this format on my DateTime index?

st.write(df) or st.dataframe(df) displays index as: 2020-01-01T00:15:00-05:00
I would like to display my table with this index format: 2020-01-01 00:15:00

Thanks in advance for your support.

If you want you can see my web project on: https://renewables-peru.herokuapp.com/

Welcome @KevinAQM to streamlit community :eyes:. First, the column you are setting to the index have this variable T as being shown in this picture you available to us? maybe the index are auto formatting T as time, because at the blue box you circled he didn’t show this parameter…

Hi, @feliperoque. My dataframe is correct, the index too.

When I print: df.index I get that, in the blue box: 2020-01-01 00:15:00. That is a proof my dataindex format is OK.

The problem occurs when I display the table with st.write(df) or st.dataframe(df), Streamlit creates the table with this format: 2020-01-01T00:15:00-05:00

I hope you can help me. I really like the style of that table, but I would like the dates to be readable and easy for the user to understand. (2020-01-01 00:15:00 :white_check_mark:)

Have a nice day!

@KevinAQM check this out, i think it’s not a problem but the way you used numpy. Here you can see the same format as you have in your index, with this T.

https://numpy.org/doc/stable/reference/arrays.datetime.html

In this screeshot i took from you image, you can see the type of your index wich are datatime64[ns], which also return this T. I may think you gonna need to change the dtype from datetime64[ns] to another type.

121212

This could also help:

OBS: Be aware, since this post is not a streamlit problem (is more python syntax), people here may not help you. Try to post this on stackoverflow, it’s more suitable.

Hi @KevinAQM, I know this thread is already 3 months old but I think I have found the solution after searching around for it. I’m not sure if it’s still something you’re looking for, but looking at your heroku app, you still haven’t really found the solution to it. I had the same predicament too and then realized that I need to look into the way PyArrow handles Pandas dataframe conversions.

Have you tried to convert your DateTime column in your Pandas df to strftime format prior to passing it into st.write() or st.dataframe() as such?

df["Date"] = pd.to_datetime(df["Date"])
df["Date"] = df["Date"].dt.strftime("%Y-%m-%d %H:%M:%S")

I have tested it on my code and it works perfectly great for me, so let me know if it does for you! :smiley:

1 Like

Hello there, @bengsoon:

That works! Thank you so much for your time, my friend.

Have a good day.

1 Like