date

Create extra rows using date column pandas dataframe

Create extra rows using date column pandas dataframe Question: Imagine I have the following data: ID Leave Type Start Date End Date 1 Sick 2022-01-01 2022-01-01 1 Holiday 2023-03-28 2 Holiday 2023-01-01 2023-01-02 3 Work 2023-01-01 2023-01-01 I need to find a way to confirm Start Date and End Date have the same value. In …

Total answers: 3

Is there a way to subtract from the date a year specified in another column in python?

Is there a way to subtract from the date a year specified in another column in python? Question: Today I have confronted some challenges. This is an example dataset: example = { "a": [‘1/1/1954 14:14′,’2/14/2001 2:00’ , ‘2/15/2002 12:00’], "b": [1936,1996,1960], } #load into df: example = pd.DataFrame(example) print(example) What I was trying to do …

Total answers: 1

Compute a combined difference of two columns and a running difference in a column

Compute a combined difference of two columns and a running difference in a column Question: If there are duplicate IDs, Diff is the next End_Date minus the previous End_Date and Diff is End_Date minus Start_Date for the last duplicate ID, otherwise Diff is also End_Date minus Start_Date. My data set looks like the following: df …

Total answers: 1

How to include start and end date in pandas groupby/Grouper?

How to include start and end date in pandas groupby/Grouper? Question: I have a example DataFrame below. import pandas as pd df = pd.DataFrame({ ‘date’:["2022-01-01", "2022-02-01", "2022-03-01", "2022-04-01", "2022-05-01", "2022-06-01"], ‘amount’: [2,4,3,5,6,4], ‘category’: [‘credit’, ‘credit’, ‘debit’, ‘credit’, ‘debit’, ‘credit’]}) df.date = pd.to_datetime(df.date) print(df) date amount category 0 2022-01-01 2 credit 1 2022-02-01 4 credit 2 …

Total answers: 1

Looping through ("Spanning across") dates in Python with variable months and years?

Looping through ("Spanning across") dates in Python with variable months and years? Question: My requirement is to loop through calendar dates in python in 2-day increments capturing every date across multiple months or years without repeating any dates. I’m sure that sounds confusing so I’ve posted some reference visuals to demonstrate. I have written Python …

Total answers: 2

Context variables not being passed to template in Django class-based view

Context variables not being passed to template in Django class-based view Question: Banging my head against a wall.. I’m trying to return a table of Job objects, with views separated by month. I’m passing ‘year’ and ‘month’ variables through get_context_data, yet in my template they’re returning blank strings. Even ChatGPT can’t find anything wrong lol. …

Total answers: 1

How can I sort my dates in a numpy array in order?

How can I sort my dates in a numpy array in order? Question: I have this numpy array called all_periods: array([’01/01/2021′, ’01/01/2022′, ’02/01/2021′, ’02/01/2022′, ’03/01/2020′, ’03/01/2021′, ’03/01/2022′, ’04/01/2020′, ’04/01/2021′, ’04/01/2022′, ’05/01/2020′, ’05/01/2021′, ’06/01/2020′, ’06/01/2021′, ’07/01/2020′, ’07/01/2021′, ’08/01/2020′, ’08/01/2021′, ’09/01/2020′, ’09/01/2021′, ’10/01/2020′, ’10/01/2021′, ’11/01/2020′, ’11/01/2021′, ’12/01/2020′, ’12/01/2021′], dtype=object) I want to sort this by day, month …

Total answers: 4

Creating a column that takes a Week Number and Year and returns a Date

Creating a column that takes a Week Number and Year and returns a Date Question: I’m currently working with a dataframe where I created a Year and Week # column. I’m trying to create a new column Date that gives me the date for a from the Year and Week # columns. This is what …

Total answers: 2