Getting the real value instead of the text "a few seconds"

Hello:

I’m just starting with Streamlit, hope is a fun journey!!!

I have a vey simple app which is connecting to a dBMaria database. The database has a column with time values of this type: 00:34:16.6367.
(Witch is representig hours:minutes:seconds.Thousands of miliseconds), this is the column in DbMaria:

image

And this is the code in Python for displaing the data:

result_dataFrame = pd.read_sql(“SELECT * FROM Vuelta”,db)
st.write(result_dataFrame)

And I get this:

image

What can I do so the table displays the actual values instead o “a few seconds” or “34 minutes”?

Thanks in advance.

Using this formula:
column_config{“tiempo”:st.column_config.TimeColumn(format=“HH:mm:ss:SSSS”)}

I get incorrect values but correct format:
image

If I change the formula to this:

column_config{“tiempo”:st.column_config.NumberColumn(format=“%.2d”)}

I get correct values but incorrect format:
image

This are the correct values and correct format coming from dBMaria column, type of column is “TIME”.

image

Any clue?

What is the dtype of the column?

result_dataFrame["tiempo"].dtype
1 Like

Thanks for the reply, this is what I gert:

dtype(‘<m8[ns]’)

How does 20510200000 represent 21.0079 seconds?

1 Like

Never mind. I need to figure out what the actual values are. "<m8[ns]" means "datetime64[ns]", so the values carry date information but somehow streamlit knows it must discard it. What is the first value?

repr(result_dataFrame["tiempo"].iloc[0])
1 Like

Thanks for your support.

For examplo, just check the final values of the three tables of my last post:

Correct value from dbMaria (third table):
00:00:20:1030 (is 20 seconds and 1030 thousands of a second)

Using:
> column_config{“tiempo”:st.column_config.NumberColumn(format=“%.2d”)}
I get: 201030000
So values are correct, but I loose the format.

And if I use:

> column_config{“tiempo”:st.column_config.TimeColumn(format=“HH:mm:ss:SSSS”)}

I get 16:10:00:0000
Which is correct format but wrong value (I don’t know what type of conversion is streamlit doing…)

Is it clear now?

I am looking for the actual values stored in result_dataFrame["tiempo"]:

repr(result_dataFrame["tiempo"].iloc[0])
1 Like

This is what I get:

“Timedelta(‘0 days 00:00:20.103000’)”

(just notice is not first register, is the last one.)

That is weird. Are you sure about the dtype? dtype('<m8[ns]') can’t store timedeltas, I think. I am unable to store timedeltas in a Series with that dtype.

1 Like

Yes, here you can see:

Neither streamlit nor pandas have a way of formatting timedeltas, as far as I know. Of course you can roll your own.

This would be a simple approach (assuming the durations are always < 1 day):

def tdformat(td):
    return str(delta)[7:]

result_dataFrame["tiempo"] = result_dataFrame["tiempo"].apply(lambda td: str(td)[7:])
1 Like

Thanks, now is ok!!!

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