Search code examples
pythondatetimestrptime

How can I convert a str type to date type using python


I'm trying to convert a str type ( like :"1995-01-09 00:00:00") to date, here is my attempt

for line in ratings_df[['user_id','movie_id','rating','timestamp']].values:
    annee= line[3]
    print datetime.strptime(annee, "%Y-%m-%d %H:%M:%S")

and I got this error:

error


Solution

  • Try printing value of the variable annee first. This might solve the problem.