[Python] How to read long digits from Excel by Pandas and add apostrophe to cells?

Discussão em 'Python' iniciado por Stack, Maio 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have an excel file where one line contains id that is 16-digit number.
    It looks like:

    item1 item2 item3
    1234567890123456 1234567866623000 1234567877722000
    1320 800 201
    2019-01-05 2020-01-04 2017-06-05


    I use python and pandas to read it.
    When I read it by pandas some ids are malformed - last digits are different, i.e. 1234567866623000 becomes 1234567866622992.
    I think it is because excel has 15-digits precision, but my ids are 16 digits.
    Code that reads excel file is:

    import pandas as pd
    ...
    df = pd.read_excel(filepath, sheet_name='MyList', header=None)


    When I convert cells to str type in pandas some ids are still malformed.
    But when I add apostrophe ' before each id in excel file it becomes the text type in excel and then pandas reads values correctly without loss of precision.
    How do I add apostrophe in the begginging of every cell in one row using pandas?
    Or is it any better way to read 16-digits id from excel?

    Continue reading...

Compartilhe esta Página