Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

   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'

>Solution :

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]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading