0

I'm trying to create a function that convert a date into a single number which represent a number of that day between two dates. I will import set of data from my Dataframe and I will add these numbers to a new column (the value of these cells depends on the date on the other column).

for example; any date that handle '1/1/1990' will return 1 and '2/1/1990' will return 2 and so on until '30/12/2000'.

I tried with this code but it gave me a total days. Any suggestion?

import datetime
from dateutil.parser import parse

    def get_x_days_ago(date_from, current_date = None):
        if current_date is None:
            current_date = datetime.datetime.today()
        return (current_date - date_from).days
    
    date_from = parse('1/1/1990')
    date_to = parse('30/12/2000')
    days = get_x_days_ago(date_from, date_to)
    #print(days)
    
    df['days'] = days
    new_df = df.copy()
    df

sorry but there is no relation between my question and the other question that you mention here. How to apply a function to two columns of Pandas dataframe

gtrfexws
  • 53
  • 1
  • 8

0 Answers0