Time field without year/month/day

Hi guys.

I have in postgres a column of type TimeField, it stores only time (hour, minute, seconds …)
After transforming this data into a dataframe it is presented as below:


As you can see above some records come complete and others only with hour, minute and seconds

In the dataframe it is of type object, that is, if I want to filter by an interval I already know that I won’t be able to.

What would be the best way to make a filter like this?
What would be a way to transform it into an object that allows me to filter by time interval?

Hi @EliasCoutinho , what do you mean by complete? I only see HH:MM:SS . Arent the last few numbers just decimals of the seconds?

Exactly, some have it and some don’t.

Haha, OK. But should the all the values have decimals?

You don’t need decimals.

I am sorry, I don’t understand the problem and waht you want to do. :thinking:

Hello @EliasCoutinho,

It sounds like you just need to create a uniform format to display the data in the table.

For example, you can either apply ‘.000000’ to the remaining ones who do not have the milliseconds.
Or, apply it in reverse and remove the milliseconds.

If you add, then you would be able to filter by interval.

Can you show what it would look like to remove the milliseconds?

You mean, how would you convert to remove the milliseconds via code?

Yes, to use on pandas.

Sure, here is a simple way:

import pandas as pd

df = pd.DataFrame({

for i, r in df.iterrows():
    r['timestamp'] = r['timestamp'].split('.')[0]


Keep in mind, there mind be some other ways to accomplish this.

1 Like