Reputation: 664
How should I convert the time '14:12:2006' , '1200' and '1500' into pandas datetime with just the time part so that I can check if the first time is between the other two.
What I am looking for is:
12:00 < 14:12:2006 < 15:00
I just need the conversion, not the comparison.
Upvotes: 2
Views: 1426
Reputation: 323226
If you only need to compare the them , you can do with
s=pd.Series(['14:12:2006' , '1200' , '1500']).str.replace(':','').astype(str)
s=s.str.ljust(s.str.len().max(),'0').astype(int)
s.iloc[1]<s.iloc[0]<s.iloc[2]
True
s
0 14122006
1 12000000
2 15000000
dtype: int64
Upvotes: 1