Pandas : Chaning date to a format where I can use `map`

Question:

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'

Asked By: Scope

||

Answers:

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]
Answered By: Corralien
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.