Skip to content

Integers converted to floats when round-tripping through Excel #4932

Closed
@jtratner

Description

@jtratner

0.12 and current master have this problem (problem is that we were only testing frames with floats):

>>> df = DataFrame(range(10))
>>> df.dtypes
0    int64
dtype: object
>>> df.index
Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64)
>>> df.to_excel('test1.xlsx')
>>> new_df = read_excel('test1.xlsx', 'sheet1')
>>> new_df.index
Index([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], dtype=object)
>>> new_df.dtypes
0    float64
dtype: object

Can we do some type inference here or something? read_csv handles it better:

>>> df.to_csv('out.csv')
>>> new_df = read_csv('out.csv')
>>> new_df.index
Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64)
>>> new_df.dtypes
Unnamed: 0    int64
0             int64
dtype: object

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions