Skip to content

Leading zeros in data for read_excel vs read_csv #46895

Closed
@ppinkhasov

Description

@ppinkhasov

input file is 6 random zip codes. the first one being "02494" with a column header called 'Zip'

test_file = pd.read_excel("test_zips.xlsx", header=0, dtype={'Zip':object})
print(test_file)

print("\n")

test_file = pd.read_excel("test_zips.xlsx", header=0, converters = {'Zip': str})
print(test_file)

output


     Zip
0   2494
1  12010
2  97007
3  14224
4  80922
5  12205


     Zip
0   2494
1  12010
2  97007
3  14224
4  80922
5  12205`


-- but using read_csv works fine

as you can see leading 0 is there.

image.png

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions