Skip to content

Datatype of Integer changes depending on indexing method on a dataframe with an integer and a float column #14205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Khris777 opened this issue Sep 12, 2016 · 1 comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@Khris777
Copy link

Take a dataframe that has one integer and one float column, then use various methods to get the first integer element. In certain cases the datatype will be given back correctly as int64, in other cases however it's changed to float64. Indexing using ix even does both, depending on how it is used:

import pandas as pd

DD = {'I':[1,2,3,4,5,6,7,8,9,10],'F':[1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,10.1]}
DF = pd.DataFrame(DD)

print "Direct index:"
print DF['I'][0]
print DF['I'][0].dtype
print "==========="
print "ix with name:"
print DF.ix[0,'I']
print DF.ix[0,'I'].dtype
print "==========="
print "loc of column:"
print DF['I'].loc[0]
print DF['I'].loc[0].dtype
print "==========="
print "iloc of column:"
print DF['I'].iloc[0]
print DF['I'].iloc[0].dtype
print "==========="
print "ix of column:"
print DF['I'].ix[0]
print DF['I'].ix[0].dtype
print "====================="
print "Values:"
print DF.values[0,1]
print DF.values[0,1].dtype
print "==========="
print "ix with index:"
print DF.ix[0,1]
print DF.ix[0,1].dtype
print "==========="
print "loc:"
print DF.loc[0,'I']
print DF.loc[0,'I'].dtype
print "==========="
print "iloc:"
print DF.iloc[0,1]
print DF.iloc[0,1].dtype

Expected Output

Direct index:
1
int64
===========
ix with name:
1
int64
===========
loc of column:
1
int64
===========
iloc of column:
1
int64
===========
ix of column:
1
int64
=====================
Values:
1.0
float64
===========
ix with index:
1.0
float64
===========
loc:
1.0
float64
===========
iloc:
1.0
float64

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 62 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: de_DE

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 25.1.6
Cython: 0.24
numpy: 1.11.1
scipy: 0.17.1
statsmodels: None
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.1
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: 0.2.1
@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request labels Sep 12, 2016
@jreback jreback added this to the No action milestone Sep 12, 2016
@jreback
Copy link
Contributor

jreback commented Sep 12, 2016

dupe of #11617

pull-request to fix are welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

2 participants