datetime - How to change date time formats python -
i have huge data of time series , facing problem in changing time conventions.
below different types , trying make them 1 format. not able find guidance accordingly. more data pre processing/ cleaning process trying do. next execution process python , pandas goes smooth. changing manually practically impossible need fix python script.
the input files of 2 types in csv
format.
a 3 column , multiple rows col[0]
date-time , rest other data. column header not constant every input file given name cannot use headers.
09/30/2015 12:00 pm,abcsd,434235 09/30/2015 12:30 pm,taer,45824 09/30/2015 13:00 pm,hshfe,4894
the input file multiple columns , multiple rows
no.,30-09-2015 12:00 pm,30-09-2015 13:00 pm 1111,2345,2342
types
1. 09/30/2015 12:00:00 2. 30/09/2015 12:00 3. 09/30/2015 12:00 pm 4. 30/09/2015 12:00 pm 5. 30-09-2015 12:00:00 6. 30-09-2015 12:00 pm
the above listed types , want bring them 1 format as:
1. 30/09/2015 12:00 or 2. 09/30/2015 12:00
i not find proper guidance in document too. not try out code far.
thanks valuable suggestions
you need read them common datetime object, print them out object.
unfortunately best way read in multiple formats have list of possible formats , try using each one.
for example:
import datetime possible_formats = ['%h%m%s', ...] date in dates: format in possible_formats: try: formatted = datetime.strptime(date, format) print formatted # same format every time break # found it, stop trying formats except: pass # wrong format, keep trying formats
Comments
Post a Comment