Skip to content
Advertisement

Tag: datetime

Combining weeks 52 and 0 with Python Datetime

I have a Pandas DataFrame with daily data that I’m trying to group by week number to sum some columns, and I notice that when years do not begin on Sunday, the data for the week spanning the end of one year and the beginning of the next do not cleanly sum, instead being broken into two groups. My code

Matplotlib dates.DateFormatter forcing the display of nanoseconds

I encounter an issue with Matplotlib.dates.DateFormatter : I want to convert timestamps in Date format which is simple usually with the straftime but when using it on matplotlib i don’t have the dynamic position on my graph so I used the md.DateFormatter(‘%H:%M:%S.%f’) to have the X values as a date format with the dynamic index. The fact is, my dates

Separate columns of a DataFrame by days of the week

Let it be the following Python Panda Dataframe (the original could include dates for several months): Hours 2022-06-06 2022-06-07 2022-06-08 2022-06-09 2022-06-10 2022-06-11 2022-06-12 2022-06-13 2022-06-14 2022-06-15 2022-06-16 2022-06-17 2022-06-18 2022-06-19 00:00 3 0 0 3 23 43 1 2 3 3 7 3 1 0 05:00 5 4 0 3 32 31 3 9 3 3 5 3 0

how to divide a datetime object by an int

I can’t seem to divide a datetime.time object by an int. Looking at the documentation I can’t figure out why it isn’t working. I get the error: unsupported operand type(s) for /: ‘datetime.time’ and ‘int’. I did see a method that splits the time down into second then performs the division on the number of seconds, but wondering if there

Pandas dataframe – fillna with last of next month

I’ve been staring at this way too long and I think Ive lost my mind, it really shouldn’t be as complicated as I’m making it. I have a df: Date1 Date2 2022-04-01 2022-06-17 2022-04-15 2022-04-15 2022-03-03 NaT 2022-04-22 NaT 2022-05-06 2022-06-06 I want to fill the blanks in ‘Date2’ where it keeps the values from ‘Date2’ if they are present

Advertisement