0

I hope everyone is well. I am trying to create a new column that requires the values from two different columns ("Task Start Date" and "Hours"). I am trying to use the apply function but i cant figure out the correct syntax.

def get_start_date(end_date, day):

    date_format = '%d-%b-%y'
    date = datetime.strptime(end_date, date_format)
    start_date = date - timedelta(days = day)
    return start_date

asana_filtered["Task Start Date"] = asana_filtered.apply(get_start_date(["Task Due Date"], ["Days"]))
dodoelhos
  • 147
  • 1
  • 12

2 Answers2

0

Found it!

python pandas- apply function with two arguments to columns

asana_filtered["Task Start Date"] = asana_filtered.apply(lambda x: get_start_date(x["Task Due Date"], x["Days"]), axis=1)
dodoelhos
  • 147
  • 1
  • 12
0

You can use the native pandas time converters:

df["Task Start Date"] = pd.to_datetime(df["Task Due Date"]) - pd.to_timedelta(df["Days"], unit="D")
Oleg O
  • 1,005
  • 6
  • 11