Skip to content

BUG: DataFrame.loc[] returns object type instead of float #63071

@thanhlecongg

Description

@thanhlecongg

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

from pandas import DataFrame


df_e = DataFrame([["x", 10.0, 20.0], ["y", 30.0, 40.0]])
print(df_e.loc[0, slice(1, 3)])

Issue Description

When selecting columns using slices from a DataFrame that contains mixed data types, the resulting columns always have the dtype object, even when all the selected elements share the same data type (for example, float64). This issue was previously reported and fixed for array-based column selection in Issue #60600, but it still occurs when selecting columns with slices.

Expected Behavior

# Current Output: 
1    10.0
2    20.0
Name: 0, dtype: object


# Expected Output: 
1    10.0
2    20.0
Name: 0, dtype: float64

Installed Versions

commit : 9c8bc3e python : 3.13.9 python-bits : 64 OS : Darwin OS-release : 24.6.0 Version : Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:29 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6000 machine : arm64 processor : arm byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 2.3.3
numpy : 2.3.4
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 25.2
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 22.0.0
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : N/A
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions