Home > Software engineering >  Pandas : Chaning date to a format where I can use `map`
Pandas : Chaning date to a format where I can use `map`

Time:01-24

Im trying to get current data in string format (Month-Date-Year)

def user_defined_function(date_str): I have a user defined function which takes input date(refresh_date) in the above mentioned format. So I need to change the today's date to the required format and map it.

What I Tried :

   import datetime as dt
   from datetime import date
   refresh_date=date.today().strftime('%m-%d-%Y')
   x=refresh_date.map(user_defined_function).values[0]

I am however getting an error using the above code AttributeError: 'str' object has no attribute 'map'

CodePudding user response:

Create a Series with your refresh_date variable:

refresh_date = pd.Series([date.today().strftime('%m-%d-%Y')])
x = refresh_date.map(user_defined_function).values[0]
  • Related