Skip to content
Advertisement

Tag: datetime

How to calculate total difference in milliseconds by condition?

I have the following pandas dataframe df: timestamp version actual pred 2022-01-19 11:00:00.600 1 0 0 2022-01-19 11:00:00.800 1 0 1 2022-01-19 11:00:01.200 1 1 0 2022-01-19 11:00:01.800 1 0 0 2022-01-19 11:00:02.200 2 1 1 2022-01-19 11:00:02.600 2 0 0 2022-01-19 11:00:03.200 3 0 1 2022-01-19 11:00:03.600 3 0 0 2022-01-19 11:00:03.800 3 1 0 2022-01-19 11:00:03.600 4 0

Remove data time older than specific hours

I want to remove data from my dataframe older than say 2 hours from current time starting with 00 mins (datetime column is in index) when i use below code Current datetime: ’17-03-2022 17:05:00′ Issue: My code keeps all records in df from ’17-03-2022 15:05:00′ to ’17-03-2022 17:05:00′ Requirement: All records in df from ’17-03-2022 15:00:00′ to ’17-03-2022 17:05:00′ It

Get cumulative sum in pandas

Context Datetime Campaign_name Status Open_time 2022-03-15 00:00 Funny_campaign Open 2022-03-15 01:00 Funny_campaign Continue 2022-03-15 02:00 Funny_campaign Continue 2022-03-15 03:00 Funny_campaign Continue 2022-03-15 04:00 Funny_campaign Close 2022-03-15 08:00 Funny_campaign Open 2022-03-15 09:00 Funny_campaign Continue 2022-03-15 10:00 Funny_campaign Close Problem I need to calculate the time from open to close. My code right now There are two approches I could go with.

Is pandas.read_spss misreading datetime into unix?

I have a sav file with a datetime column in %m/%d/%Y string format. When I read it in with pd.read_spss(), which doesn’t seem to have any datetime-related arguments, it ends up in what looks like unix time, except that the time would be a few centuries from now with unique values including 13778726400, 13841884800, etc. When I feed the read

CET timezone strings to datetime

I have a data frame that has columns looking similar to this. This data is imported from SQL into a Pandas data frame, and when I print out the dtypes I can see that the date_cet column is object. Since I need it further on, I want to convert it to a datetime object. However, the stuff I’ve tried just

Advertisement