python-datetime

How to get the last date of the current week or quarter in python?

How to get the last date of the current week or quarter in python? Question: I would like to find a simple way to get the last date of the current week or quarter. To get the last date of the current month I can use the relativdelta function from dateutil: import pandas as pd …

Total answers: 1

If condition is True run all cells below in a Jupyter Notebook

If condition is True run all cells below in a Jupyter Notebook Question: I am creating a basic ETL script in Jupyter Notebook that refreshes data daily in a Google Sheet. However, sometimes the database is not updated on it’s scheduled time due to a failed load, etc. I have created this line to verify …

Total answers: 1

Python how to format a string time from number time to name time

Python how to format a string time from number time to name time Question: I have a string time : ctime = ‘Thu Sep 1 12:25:26 2022’ How can I format it to : 01 Sep 2022 12:25:26 I have tried: ctime .strftime("%d %m %Y, %H:%M:%S") But received: AttributeError: ‘str’ object has no attribute ‘strftime’ …

Total answers: 1

How can I print a day and a time using Python strftime?

How can I print a day and a time using Python strftime? Question: how can I print a day and a time using Python strftime? My code is below, but any time I run it, I get "ValueError: time data ‘1 day, 2:45:00’ does not match format ‘%H:%M:%S’" . I want the output to be …

Total answers: 1

How to include "origin" into "fromtimestamp" function of "datetime" module

How to include "origin" into "fromtimestamp" function of "datetime" module Question: I want the program to display time stamp, when seconds are given as input. But the origin year in jupyter notebook starts from 1970-01-01. I want to make the origin as 1980-01-01. Can somebody help. I tried this, but how can i include the …

Total answers: 2

Python Datetime Subtration include 0 to hour section

Python Datetime Subtraction include 0 to hour section Question: I’ve 2 strings of datetime, I need to subtract those to get duration but when subtracted for hour section it only contain 1 digit eg: 1:30, 2:30 So, my question is can we get subtracted datetime or string which includes 0 at the beginning eg: 01:30, …

Total answers: 2

Does the unit passed to the datetime64 data type in pandas do anything?

Does the unit passed to the datetime64 data type in pandas do anything? Question: Does the unit passed to the datetime64 data type in pandas do anything? Consider this code: import pandas as pd v1 = pd.DataFrame({‘Date’:[‘2020-01-01’]*1000}).astype({‘Date’:’datetime64′}) v2 = pd.DataFrame({‘Date’:[‘2020-01-01’]*1000}).astype({‘Date’:’datetime64[ns]’}) v3 = pd.DataFrame({‘Date’:[‘2020-01-01’]*1000}).astype({‘Date’:’datetime64[ms]’}) v4 = pd.DataFrame({‘Date’:[‘2020-01-01’]*1000}).astype({‘Date’:’datetime64[s]’}) v5 = pd.DataFrame({‘Date’:[‘2020-01-01’]*1000}).astype({‘Date’:’datetime64[h]’}) v6 = pd.DataFrame({‘Date’:[‘2020-01-01’]*1000}).astype({‘Date’:’datetime64[D]’}) v7 = pd.DataFrame({‘Date’:[‘2020-01-01’]*1000}).astype({‘Date’:’datetime64[M]’}) …

Total answers: 1

how to get non continuous date time in dataframe datetime column pandas

How to extract sequence of rows in output data pandas Question: I have a datetime based dataframe as below, timestamp value … metric 36 2014-04-02 17:20:00 125.098263 … 25.098263 14 2014-04-06 16:25:00 140.072787 … 265.171050 10 2014-04-11 09:00:00 127.882020 … 393.053070 45 2014-04-11 09:05:00 115.705719 … 508.758789 24 2014-04-11 09:15:00 127.261178 … 636.019967 17 2014-04-11 …

Total answers: 1