Skip to content

print df.ix[..,..] changes dataframe? #5424

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
jankatins opened this issue Nov 3, 2013 · 3 comments · Fixed by #5426
Closed

print df.ix[..,..] changes dataframe? #5424

jankatins opened this issue Nov 3, 2013 · 3 comments · Fixed by #5426
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@jankatins
Copy link
Contributor

These two codeblocks result in different dataframes:

import pandas as pd
import numpy as np
cont = ['one', 'two','three', 'four', 'five', 'six', 'seven']
dfb = pd.DataFrame({'a' : cont, "b":cont[3:]+cont[:3] ,'c' : np.arange(7)})
#print dfb.ix[0,"c"]
dfb.ix[7,'c'] = 1
print dfb
print dfb.ix[7,"c"]
print dfb.ix[0,"c"]

       a      b  c
0    one   four  0
1    two   five  1
2  three    six  2
3   four  seven  3
4   five    one  4
5    six    two  5
6  seven  three  6
7    NaN    NaN  1
1.0
0.0

and

import pandas as pd
import numpy as np
cont = ['one', 'two','three', 'four', 'five', 'six', 'seven']
dfb = pd.DataFrame({'a' : cont, "b":cont[3:]+cont[:3] ,'c' : np.arange(7)})
print dfb.ix[0,"c"]
dfb.ix[7,'c'] = 1
print dfb
print dfb.ix[7,"c"]
print dfb.ix[0,"c"]

0
       a      b   c
0    one   four   0
1    two   five   1
2  three    six   2
3   four  seven   3
4   five    one   4
5    six    two   5
6  seven  three   6
7    NaN    NaN NaN
nan
0.0

pd.version = '0.12.0-922-gac1609e'

In the first case I also don't understand why the last column is changed to a float when I set an int.

@jtratner
Copy link
Contributor

jtratner commented Nov 3, 2013

I don't have time to look at this today, but I'm guessing it has something to do with ix maybe caching something on the Series. The change to a float is a nice pointer, because it suggests that the column was astyped to float when it gained a missing value and never changed back. Or @jreback will come in and fix it in 30 seconds with his hands tied behind his back blind-folded. :)

@jreback
Copy link
Contributor

jreback commented Nov 4, 2013

was about 10 minutes.....:) (didn't start for a while)

@jreback
Copy link
Contributor

jreback commented Nov 4, 2013

The astyping is in theory possible but I don't do it for efficiency because otherwise you have a do a semi-expensive check anytime you do pretty much anything (its in there, just not the float -> int conversions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants