i've data frame is this
In[1]: df1
Out[1]
Loan Date Negotiation
2019-03-31
2019-03-31
2019-03-31
as Loan Date Negotiation datetime64[ns]
so i wanna make function to subtract 2 days from it. if last the day of the month is sunday, i will subtract 2 days from it.
From dataframe above, 2019-03-31 Is sunday,
i've tried but it's fail, this is
def subtractingDate(dateTime):
dateTimestamp = pd.Timestamp(dateTime)
newDate = dateTimestamp - pd.Timedelta("2 days")
return newDate
dfMARET.loc[dfMARET["Loan Date Negotiation"].dt.dayofweek == 6, "New Date"] = subtractingDate(dfMARET["Loan Date Negotiation"])
*note: 6 is for sunday
So the error is
TypeError Traceback (most recent call last)
<ipython-input-9-cc2a3348e6ce> in <module>
16 # a = subtractingDate(dfMARET["Loan Date Negotiation"])
17 # a
---> 18 dfMARET.loc[dfMARET["Loan Date Negotiation"].dt.dayofweek == 6, "New Date"] = subtractingDate(dfMARET["Loan Date Negotiation"])
19 dfMARET
20
<ipython-input-9-cc2a3348e6ce> in subtractingDate(dateTime)
10
11 def subtractingDate(dateTime):
---> 12 dateTimestamp = pd.Timestamp(dateTime)
13 newDate = dateTimestamp - pd.Timedelta(days = 2)
14 return newDate
pandas\_libs\tslibs\timestamps.pyx in pandas._libs.tslibs.timestamps.Timestamp.__new__()
pandas\_libs\tslibs\conversion.pyx in pandas._libs.tslibs.conversion.convert_to_tsobject()```
so my expectation would be
Loan Date Negotiation
2019-03-29
2019-03-29
2019-03-29
Ther's solution in pandas?
thank's