Search code examples
pythonpython-3.xpandasdatetimeunix-timestamp

Python strptime missing some milliseconds when running script in different computer


I am formatting pandas dataframe timestamp column to unix timestamp as follows

from datetime import datetime

df["col_in_unix"] = df["example_col"].\
                        apply(lambda x: datetime.strptime(x, '%Y-%m-%d %H:%M:%S.%f').timestamp())

And when running this on my computer I get from a timestamp

datetime.strptime("2020-12-09 13:27:48.172793", '%Y-%m-%d %H:%M:%S.%f').timestamp()

1607513268.172793

but when I run the code in different windows pc I sometimes get answer

1607513268.17

And this happens to all timestamps in the dataframe column, what gives? I have also made .exe file from the script with Pyinstaller and still the same problem


Solution

  • I am wondering if this is not related to either:

    1. Differences in system time resolution due to different hardware / drivers, etc.
    2. precision setting for pandas and/or the dataframe
    3. Similar issue described for Windows 32b vs. 64b in C# (you are likely to observe a similar problem between 32b and 64b versions of Python).
    4. Some other factor