[Solved] Pandas Python: KeyError Date


This looks like an excel datetime format. This is called a serial date. To convert from that serial date you can do this:

data['Date'].apply(lambda x: datetime.fromtimestamp( (x - 25569) *86400.0))

Which outputs:

>>> data['Date'].apply(lambda x: datetime.fromtimestamp( (x - 25569) *86400.0))
0   2013-02-25 10:00:00.288
1   2013-02-26 10:00:00.288
2   2013-02-27 10:00:00.288
3   2013-02-28 10:00:00.288

To assign it to data['Date'] you just do:

data['Date'] = data['Date'].apply(lambda x: datetime.fromtimestamp( (x - 25569) *86400.0))

#df
                     Date  cost
0 2013-02-25 16:00:00.288   100
1 2013-02-26 16:00:00.288   101
2 2013-02-27 16:00:00.288   102
3 2013-02-28 16:00:00.288   103

solved Pandas Python: KeyError Date