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

Matplotlib - When working with datetime format a lines across the graph appear

I am trying to plot temperature over time and use the datetime format for it. But when I plot it lines are obscurring the plot seemingly random. Maybe this is due to the cyclical nature of a year? Just a thought here is the code: the column…
torakaou
  • 185
  • 1
  • 13
0
votes
2 answers

How to change time in available line in python

Let's assume there is a code which is using with anaconda prompt. While the program flowing, every second is printing to screen. However, here every second is printed the same or next line. I want to print every second in the same place. For…
dralioz
  • 49
  • 5
0
votes
2 answers

Error calculating time difference in Python

Quick question. Does someone know why I'am getting an 'Invalid Syntax' error usign this code? Thank you all. def get_time_difference(date, time_string): time_difference = datetime.now() - datetime.strptime(f"{date} {time_string}", "%d-%m-%Y…
ManCity10
  • 119
  • 1
  • 12
0
votes
2 answers

How can I get a calendar weeks start and end date in Python?

I would like to have a function get_cw_borders(year: int, cw: int) -> Tuple[datetime.datetime, datetime.datetime] which should behave like this: >>> get_cw_borders(2020, 17) (datetime.datetime(2020, 4, 20), datetime.datetime(2020, 4, 26)) >>>…
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
0
votes
1 answer

pandas plot mixing bars and lines

I have the results from two groupby operations, the first one, m_y_count, in this multiindex format (first column years and second column months): 2007 12 39 2008 1 3 2 120 2009 6 1000 2010 1 86575 2 …
0
votes
1 answer

Split the date into 1st, 2nd, 3rd, 4th week of the month

I have a data frame of dates: id|date 13|2017-01-31 12|2016-12-07 11|2013-03-19 I want to classify the dates into weather it is the 1st, 2nd, 3rd or 4th week of the month. I am using this…
dsmess
  • 67
  • 1
  • 1
  • 6
0
votes
1 answer

Write date to the top of a CSVFile python

I have this code: def write_csv(path, inputdata): with open(path, 'w', errors='ignore', newline='') as newfile: writer = csv.writer(newfile, dialect='excel') writer.writerows(inputdata) I would like to write the date at the top…
PythonIsBae
  • 368
  • 3
  • 10
0
votes
1 answer

Pyspark obtain time attributes from datetime with list comprehension

I have a pyspark dataframe df: +-------------------+ | timestamplast| +-------------------+ |2019-08-01 00:00:00| |2019-08-01 00:01:09| |2019-08-01 01:00:20| |2019-08-03 00:00:27| +-------------------+ I want to add columns…
Jeroen
  • 801
  • 6
  • 20
0
votes
1 answer

Create Time Buckets Pandas Python and Count for missing time-range

How do you group data by time buckets and count no of observation in the given bucket. If none, fill the empty time buckets with 0s. I have the following data set in a dataframe: ''' df= Time 0:10 5:00 5:00 5:02 5:03 5:05 …
0
votes
0 answers

Any solution to Unknown Timezone Warning?

I have a python script to read the news RSS feed and extract the current news. I am using datatime.now() to get the current date and extract the article for the same date. I am now getting this TimeZone Warning, and articles are being extracted for…
0
votes
1 answer

Get from pandas datetime variable day and month

I have daily data of 40 years in a pandas dataframe with columns[Index = Date, Data] and I would like to extract the data from each month with cumalative sum of the data contained in days in the order showed in the code below, that means I have to…
Andy M
  • 15
  • 5
0
votes
1 answer

How to swap day by month in a Series with python?

I have a column in which there are dates : df['Date'] Date 0 2020-25-04 1 2020-26-04 2 2020-27-04 3 2020-12-05 4 2020-06-05 Name: Date, Length: 5, dtype: datetime64[ns] I want to swap the element Day by element Month, so I can have…
K. ossama
  • 403
  • 1
  • 4
  • 15
0
votes
1 answer

Python: Calculating week number of month based on specific start and end dates

I am looking to find the current week of the month. There are many answers already on this here but i have below scenario: Week starts from Sunday-Saturday When month changes, majority of the dates should be considered. Example, 30th March 2020 is…
RSM
  • 645
  • 10
  • 25
0
votes
1 answer

UTC time in python with datetime

How can I use datetime.utcnow() and datetime.date.today() together? In case I am running code A it throws error and Code B other one. I want to use both of these in my code. A from datetime import datetime, timedelta path =…
Andrew
  • 183
  • 2
  • 14
0
votes
2 answers

Python previous month with 2 digit

I want 04 as output in premonth . Can some one help on this? tried diff format and no luck. enter code here premonth = str(int(time.strftime('%m'))-1) tried using python date of the previous month but due to strftime restriction I am not able to…
Andrew
  • 183
  • 2
  • 14