Change the way date get displayed in a table from a pandas dataframe

Hello!

currently the date from a pandas dataframe in st.table(dataframe) gets displayed this way:

I would like to display it YYYY-MM-DD HH:MM

Thanks for your help!

1 Like

Hi @fredyonge and welcome to the forum :wave:,

You can use df.style.format function like so:

import streamlit as st
import pandas as pd
from datetime import datetime

data = {"a": [datetime.now()], "b": [datetime.now().timestamp()]}
df = pd.DataFrame(data, columns=["a", "b"])

fmt = "%d-%m-%Y %H:%M:%S"
styler = df.style.format(
    {
        "a": lambda t: t.strftime(fmt),
        "b": lambda t: datetime.fromtimestamp(t).strftime(fmt),
    }
)
st.table(styler)

Please feel free to let us know if you need any additional help.
And thanks for using Streamlit!