Questions tagged [python-datetime]

Python's built-in datetime module provides classes for manipulating dates and times in both simple and complex ways.

Python's built-in datetime module provides classes for manipulating dates and times in both simple and complex ways.

View on Python docs - for Python 2 and Python 3.

1880 questions
0
votes
1 answer

How do I resolve : value error : time data '1901-Jan' does not match format '%Y-%m

code: import pandas as pd import seaborn as sb import matplotlib.pyplot as plt import numpy as np import datetime as dt %matplotlib inline def parser(x): return dt.datetime.strptime('19'+x, '%Y-%m') series =…
Pavan
  • 381
  • 1
  • 4
  • 19
0
votes
2 answers

how to use lambda function to select larger values from two python dataframes whilst comparing them by date?

I want to map through the rows of df1 and compare those with the values of df2 , by month and day, across every year in df2,leaving only the values in df1 which are larger than those in df2, to add into a new column, 'New'. df1 and df2 are of the…
Bluetail
  • 1,093
  • 2
  • 13
  • 27
0
votes
2 answers

Convert time column (object type) to datetime format

I have a separate column with HH:MM: SS object type. I want to convert object type to DateTime format. Encountering the error below. Dataset time column ["ACCIDENT_TIME]:
vishal sankar
  • 33
  • 1
  • 8
0
votes
1 answer

WhatsApp texting using webbrowser module of python

import webbrowser import time import datetime name = input('Enter the contact number of a person you want to send message in WhatsApp: ') message = input('Enter the message: ') time1 = input('Enter time in {hh:mm:ss} format: ') print(f'Time entered…
0
votes
1 answer

Convert float time to datetime or timestamp in Python

I have the following dataframe: The column Time is a string and I want to convert it either to timestamp or datetime formats. However, when I run df['Time'] = pd.to_datetime(df['Time']), I always get an error OutOfBoundsDatetime: Out of bounds…
rocker996
  • 113
  • 2
  • 7
0
votes
1 answer

python dynamic values to relativedelta function

Im trying to provide dynamic value to relativedelta function, i.e relativedelta(days=1) i would like to assign dynamic function value days, months, years to the function. Consider my situation as follows. I will get list dynamicaly as follows: Ex:…
DonOfDen
  • 3,968
  • 11
  • 62
  • 112
0
votes
0 answers

Data frame: group by datatime index and a column

I need to group the following data frame (df2) by date index and id, accumulating flag values as a count: r1 = {'id':'1', 'date':'2020-01-20', 'flag':1} r2 = {'id':'1', 'date':'2020-01-20', 'flag':1} r3 = {'id':'1', 'date':'2020-01-20',…
dokondr
  • 3,389
  • 12
  • 38
  • 62
0
votes
0 answers

Datetime unconverted data remains

this error is driving me crazy. This is an error that appears only on windows. if platform == "linux" or platform == "linux2": locale.setlocale(locale.LC_TIME, "it_IT") elif platform == "darwin": locale.setlocale(locale.LC_TIME,…
0
votes
1 answer

Convert Excel date number to datetime in Python

I want to covert a column with Excel date numbers (float) to datetime, below is the function I am trying to use: import datetime datetime.datetime.fromtimestamp(42029.0).strftime('%Y-%m-%d') Bu the result I got is: '1970-01-01',I don't think it is…
Worst SQL Noob
  • 189
  • 1
  • 5
  • 15
0
votes
1 answer

"AttributeError: Can only use .dt accessor with datetimelike values" while trying to fetch day of the week

I am getting the following error while trying to fetch the particular days of the week. The code which I have used is mentioned below: df['weekday'] = df['Date'].dt.dayofweek The date is in the following format. But, I am not able to fetch the…
Vivek
  • 336
  • 2
  • 4
  • 18
0
votes
0 answers

How to read CSV file with Pandas with timezone aware index properly?

I am trying to read a .csv file which has 1048575 rows and 3 columns, there might be some missing indexes. The .csv file looks like this CSV file I wrote this line of code to read the .csv file using…
Debayan Paul
  • 95
  • 2
  • 9
0
votes
1 answer

How to colour all bars after a certain date in a matplotlib date bar chart

I have a dataset that consists of datetime.datetime objects in a list called x and a list of ints called y. I'm plotting them like so: plt.bar(x, y) plt.show() How would I go about colouring all the bars after a given date another colour? I know I…
SImon
  • 17
  • 6
0
votes
1 answer

Python list index method behaves strange inside a class

I have a simple class where one method is to get the index of a list for s specified value given that it contains the value. The method is the get_index_at_time(time) in the class below class TimeStamp: def __init__(self): self.timeList =…
IgorLopez
  • 157
  • 1
  • 1
  • 10
0
votes
1 answer

Insert query with gettime() into SQL Server table using Python

I am having an issue putting the below SQL query into Python : insert into GERVERSION values (10, 'xxxxxxxx', 7, 4, 2, getdate(),'') Note that in SQL , I have timestamp for the getdate() part Can anyone please help me out with the right syntax to…
0
votes
1 answer

How can I define a date-time-index for a lengthy database in Pandas Python

I am struggling with setting a datimeindex with monthly data since year 1 AD, whereas I do not find the same problem with the same data with a shorter time span, say 1950 to 2020 This code works co2data_monthly = pd.read_excel(path to my…