How to change a date that is expressed as an interval to be expressed as a regular %Y-%M-%D format.
I originally had a df that looked like this:
Id Date Quantity
1000A 2018-03-22 20.0
1000A 2018-03-29 8.0
1000A 2018-03-27 4.0
1000A 2018-03-28 10.0
or:
all_data = pd.DataFrame({'Id': ['1000A','1000A','1000A','1000A'], 'Date': ['2018-03-28', '2018-04-12', '2018-05-02', '2018-06-28'], 'Quantity' : [20.0, 8.0, 4.0, 10.0]})
all_data.Date = pd.to_datetime(all_data.Date)
I applied stuff on it to get basically monthly-grouped dates going backward from today's date.
today1 = pd.to_datetime('today').normalize()
frequency1 = '30D'
Nbin1 = (today1 - all_data['Date'].min()) // pd.Timedelta(frequency1) + 1 # Number of bins
bins1 = [today1 - n * pd.Timedelta(frequency1) for n in range(Nbin1, -1, -1)]
data11 = all_data.groupby(['Id', pd.cut(all_data['Date'], bins=bins1)]).sum().fillna(0).reset_index()
the output looks like this:
Id Date Quantity
0 1000A (2018-03-02, 2018-04-01] 20.0
1 1000A (2018-04-01, 2018-05-01] 8.0
2 1000A (2018-05-01, 2018-05-31] 4.0
3 1000A (2018-05-31, 2018-06-30] 10.0
....
n. 1000A (2020-11-16, 2020-12-16] 0.0
I cannot find a way to convert the date column back into regular date format like this:
Date
2018-04-01
2018-05-01
2018-05-31
2018-06-30
I feel like I have tried every tool I could find but nothing does the tric, any help would be appreciated.