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

Check age in Tkinter using datetime

I am new to programming in python, and I want to create simple app for calculating your age based on the user input. I am using the 'datetime' module, and I found example of the program running in the terminal, but I don't know tow to link the entry…
0
votes
1 answer

Create date column from quarter and year columns

Let's say I have the following columns in a dataframe. temp = pd.DataFrame({'quarter': [1, 2, 1, 3, 4], 'year': [1994, 1995, 2001, 1997, 2014]}) How can I create a new 'date' column that represents the time with a datetime…
Danlo9
  • 133
  • 3
  • 12
0
votes
2 answers

How to modify minutes in a column of datetime object of pandas dataframe?

I'd like to convert any minutes within 10 minute interval to its 5th minute. For example, minutes between 10 and 19 are converted to 15, minutes between 20 and 29 are converted to 25 and so on. The following is an excerpt from my datetime column in…
0
votes
1 answer

How to convert an object into DateTime in pandas

I have a really messy file where there are datetime that I need to read and use it as an index. (I am adding this to clarify how it looks my data). My messy file were the datetime are located look like: 31.01.2016 13:59:13 31.01.2016 13:59:13…
Geomario
  • 152
  • 1
  • 12
0
votes
3 answers

Calculate unix timestamps for midnight

I have an interval of Unix timestamps (since 1970) starting from 1593262800000 (2020-06-27) to 1594142579000 (2020-07-07). Now, I would like to calculate all timestamps for midnight in this interval. That means midnight at 2020-06-27, midnight at…
machinery
  • 5,972
  • 12
  • 67
  • 118
0
votes
1 answer

Selecting specific rows by date in a multi-dimensional df Python

image of df I would like to select a specific date e.g 2020-07-07 and get the Adj Cls and ExMA for each of the symbols. I'm new in Python and I tried using df.loc['xy'], (xy being a specific date on the datetime) and keep getting a KeyError. Any…
0
votes
1 answer

Drop certain character in Object before converting to Datetime column in Pandas

My dataframe has a column which measures time difference in the format HH:MM:SS.000 The pandas is formed from an excel file, the column which stores time difference is an Object. However some entries have negative time difference, the negative sign…
scrubcoder
  • 63
  • 1
  • 5
0
votes
1 answer

Why is a pandas.DatetimeIndex also identified as a pd.Int64Index?

Even though the single-level index of my dataframe shown below is clearly a pd.DatetimeIndex, it is still also identified as a pd.Int64Index. In what follows, I demonstrate this behavior via printouts in the VS Code debugging…
Andreas L.
  • 3,239
  • 5
  • 26
  • 65
0
votes
1 answer

How to find and add missing dates in a dataframe of sorted dates (descending order)?

In Python, I have a DataFrame with column 'Date' (format e.g. 2020-06-26). This column is sorted in descending order: 2020-06-26, 2020-06-25, 2020-06-24... The other column 'Reviews' is made of text reviews of a website. My data can have multiple…
uk_butterfly
  • 93
  • 1
  • 2
  • 8
0
votes
2 answers

Calculating time difference between two different date formats in Python

I am trying to identify hours between two dates. Date format is not consistent between two columns The below code works when the date format is similar. How can I convert the UTC date format into normal date month year df['timebetween'] =…
EricA
  • 403
  • 2
  • 14
0
votes
1 answer

A python script to perform a basic arithmetic on a datetime

I have a csv like so: Category,Position,Name,Time A,1,Tom Smith,00:45:01.23 there are multiple rows in the same format. I am getting the time of the first place rider in category 'A', and calculating the time which is 15% above, i.e. if they take 1…
PythonIsBae
  • 368
  • 3
  • 10
0
votes
6 answers

How to convert a date into a list in python

I am writing a program that needs live dates(Means like current date). Here is the code. from datetime import date today_date = date.today() print(list(today_date)) Now I want to convert this date into a list. But it gives me an error because the…
hmood
  • 603
  • 7
  • 25
0
votes
2 answers

Python: Issue with difference between dates

I want to compare two dates and get the difference in seconds, such as get the seconds between a deadline and current datetime, but I'm getting some unexpected result when the subtrahend is greater than minuend import datetime …
0
votes
1 answer

Datetime and suntime, TypeError: can't subtract offset-naive and offset-aware datetimes

import datetime from suntime import Sun, SunTimeException from datetime import timedelta def day_night_time(lat,long,TO_date,TO_time): sun = Sun(lat,long) date = datetime.date(int(TO_date[:4]), int(TO_date[5:7]), int(TO_date[8:10])) TO…
tedioustortoise
  • 259
  • 3
  • 20
0
votes
0 answers

Recommmendations on build a column with multiconditions

I posted a question similar before, but perhaps I was not clear with the info that I provided. I would like to introduce the values (Supervazio, Vazio...) in 1 column (Tariff) of an existing dataframe based on 2 weekly schedules (Summer and…
PMendes
  • 29
  • 4