[Python] Getting value from excel sheet with leading zeros [duplicate]

Discussão em 'Python' iniciado por Stack, Março 31, 2025.

  1. Stack

    Stack Membro Participativo

    I have an excel spreadsheet I'm trying to extract data from using python3 & pandas

    One of the columns contains UPC codes which may have leading zeros.

    I can't seem to figure out how to preserve this data. I've tried using "astype" on the dataframe and on the individual fields, but neither approach preserves the leading zeros.

    df = pd.read_excel('sheet.xlsx', sheet_name='Sheet1')
    df = df.astype(str)
    for row in range(df.shape[0]):
    upc = df.iat[row,0].astype(str)

    Continue reading...

Compartilhe esta Página