python-datetime

python string convert to datetime doesn't work

python string convert to datetime doesn't work Question: I’m trying to convert a string, I got from my program, to datetime.dateime but it doesn’t seem to work because I have the wrong format? The thing is, I have the right format… Here is some code: from datetime import datetime Timer = "27.10.2022 • 08:24:03" Timer …

Total answers: 1

Add custom minor ticks to plot with dates on the x-axis

Add custom minor ticks to plot with dates on the x-axis Question: I’m trying to add custom labels for some special x-values on a plot that has datetimes on the x-axis. Here is a sample of the plot: from matplotlib import pyplot as plt from matplotlib.dates import AutoDateLocator, ConciseDateFormatter import numpy as np x = …

Total answers: 1

(python) datetime.timedelta dates difference result converting to all days or minutes

datetime.timedelta dates difference result converting to all days or minutes Question: How can I make my datetime.timedelta result shows all in days or minutes? My expected output is: minute left: 7023 min days left: 5.002 day My code: aaa = "2017-09/19 07:11:00" bbb = "2017-09/24 07:14:00" result = parser.parse(bbb) – parser.parse(aaa) print(result) print(type(result)) The output: …

Total answers: 2

Difference in time between successive dataframe rows

Difference in time between successive dataframe rows Question: Similar to this question, I would like to compute the time difference between rows of a dataframe. Unlike that question however, the difference should be by groupby id. So foe example, this dataframe: df = pd.DataFrame( {‘id’: [6,6,6,6,6,10,10,10,10,10], ‘timestamp’: [‘2016-04-01 00:04:00′,’2016-04-01 00:04:20′,’2016-04-01 00:04:30’, ‘2016-04-01 00:04:35′,’2016-04-01 00:04:54′,’2016-04-30 13:04:59’, …

Total answers: 2

Python pandas creating datetime for Week and Year and Month and Year

Python pandas creating datetime for Week and Year and Month and Year Question: I’m have a pandas dataframe with : Branch, Year, Month, Week, Assignments, Sales Volume I copied your format="%Y-%m" in the hope to get the same formatted datetime.. but no. In the following I will show you my code and the result of …

Total answers: 1

Python datetime only returning negative numbers?

Python datetime only returning negative numbers? Question: I have the following code: commit_date = get_last_commit_date() # returns datetime obj: 2022-08-25 13:32:12 pr_date = datetime.fromisoformat(ISO_CODE) # returns 2022-08-24 19:15:07 Notice how commit_date is Aug. 25 and pr_date is Aug. 24. I want to find the difference in days which should be 1 day. Now doing print((pr_date …

Total answers: 1

How Can I Convert datetime.timedelta to int?

How Can I Convert datetime.timedelta to int? Question: I wrote these codes for prediction and test accuracy on some dataset with the help of sklearn random forest classifier. Code a = datetime.datetime.now() y_pred=clf.predict(X_test) b = datetime.datetime.now() rf_time = b-a rf_ac = metrics.accuracy_score(y_test, y_pred) print(type(rf_time)) print(‘Random Forest Time Duration – ‘,b-a) print("Random Forest Accuracy:",metrics.accuracy_score(y_test, y_pred)) Output …

Total answers: 2

Python – Convert 5 digit date to datetime from SAS date

Python – Convert 5 digit date to datetime from SAS date Question: I have a 5 digit date variable that was exported from SAS. I am having trouble converting it into a datetime format in Python. The variable is currently stored as an object. Here is a background on SAS dates: "The SAS System represents …

Total answers: 2