Integer Date From Spss To Python Date
I have dates imported from SPSS to Python via pandas. The dates are imported as integers (ordinal). For instance the date '2015-08-02' is imported as 13657852800. When I try pd.to_
Solution 1:
After some time, I came up with a solution to this. To make the origins of SPSS and Python match each other is necessary to rescale the integer from SPSS with the number 12219379200
i.e. the number of seconds existing between "1582-10-14"
and "1970-01-01"
(the origin used by to_datetime
)
pd.to_datetime(13657852800-12219379200, unit="s")
Returns
Timestamp('2015-08-0200:00:00')
Solution 2:
The problem here is that pandas have the min and max boundary for datetime object
pd.Timestamp.min
Out[349]: Timestamp('1677-09-21 00:12:43.145225')
pd.Timestamp.max
Out[350]: Timestamp('2262-04-11 23:47:16.854775807')
But in SPSS I think the min will be on year 1582, and possible way for this problem
pd.to_datetime((13657852800/86400)-141428, unit='D')
Out[348]: Timestamp('2015-08-02 00:00:00')
Post a Comment for "Integer Date From Spss To Python Date"