Closed
Description
A small, complete example of the issue
In [37]: df = pd.DataFrame(dict(a=[0,1,2,3],b=[0.0,1.0,2.0,3.0]))
In [38]: df
Out[38]:
a b
0 0 0.0
1 1 1.0
2 2 2.0
3 3 3.0
In [39]: df.dtypes
Out[39]:
a int64
b float64
dtype: object
In [40]: df.iloc[0]
Out[40]:
a 0.0
b 0.0
Name: 0, dtype: float64
In [41]: df.loc[1,'a']
Out[41]: 1.0
Expected Output
Any values from column 'a' should still be ints.
Output of pd.show_versions()
## INSTALLED VERSIONS
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Darwin
OS-release: 15.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 23.0.0
Cython: 0.24
numpy: 1.11.1
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.2.0
sphinx: 1.4.1
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: 1.1.0
tables: 3.2.2
numexpr: 2.6.0
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.2
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.40.0
pandas_datareader: None
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Selecting an element or row of mixed int/float DataFrame returns a row with all floats[/-][+]Selecting an element or row of mixed int/float DataFrame returns all floats[/+]TomAugspurger commentedon Oct 6, 2016
Your
Out[40]
is the correct behavior, since a Series (which is what that slice returns) can only have a single dtype, the int will be cast to a float.I thought we had an open issue for your
Out[41]
, but wasn't able to find it; thanks for reporting it.sinhrks commentedon Oct 6, 2016
Out[41]
is a dupe with #11617. Thx for the report.nileracecrew commentedon Oct 6, 2016
It could be returned as
object
, which what happens when some columns are non-numeric. But I guess this is done for understandable performance reasons.Thanks.