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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -