Home > Software design >  Convert incorrect excel date from integer to date but in pandas
Convert incorrect excel date from integer to date but in pandas

Time:11-10

there is an incorrect date - 44288.

In excel i can change format and get 02.04.2021, but how to get this result in pandas?

CodePudding user response:

This has been done similarly in: Convert Excel style date with pandas

However, with this you just add abs() to turn the negative integer into a positive, if you want it done for all in a column:

import datetime
import pandas as pd

df = pd.DataFrame({'date':[-44288,-44289]})

df['date'] = pd.TimedeltaIndex(abs(df['date']),unit='d')   datetime.datetime(1899, 12, 30)

Output:

        date
0 2021-04-02
1 2021-04-03
  • Related