How to deal with multiple date string formats in a python series -
i have csv file trying complete operations on. have created dataframe 1 column titled "start_date" has date of warranty start. problem have encountered format of date not consistent. know number of days passed today's calendar date , date warranty started product.
two examples of entries in start_date series:
9/11/15 9/11/15 0:00
how can identify each of these formats , treat them accordingly?
unfortunately have try each format might be. if give example format, strptime attempt parse discussed here.
the code end looking like:
import datetime possible_formats = ['%m/%d/%y', '%y/%m/%d', etc...] # formats date might in format in possible_formats : try: parsed_date = datetime.strptime(raw_string_date, format) # try date break # if correct format, don't test other formats except valueerror: pass # if incorrect format, keep trying other formats
Comments
Post a Comment