Converting object to pd.datetime went wrong, differ from I get in Jupyter notebook


df[‘logTime’] = pd.to_datetime(df[‘logTime’]).dt.floor(‘H’).dt.time

I tried to convert the datatime object. when I used jupyter it what I want, but when I deployed to streamlit I get numbers. ?
how to return the time object properly.
below what I get in jupyter

jupdt

If you’re looking for a specific output format, your best bet is to use strftime to specify it

import pandas as pd
import streamlit as st

# Make dataframe with a logTime column containing time strings
df = pd.DataFrame(
    {
        "logTime": [
            "02:01:00.000000000",
            "03:02:00.000000000",
            "04:03:00.000000000",
            "05:04:00.000000000",
        ]
    }
)

st.write(df)

df["logTime"] = pd.to_datetime(df["logTime"]).dt.floor("H").dt.strftime("%H:%M:%S")

st.write(df)

Which yields

2 Likes

Waw, Hello, thank you . you really saved my day

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