Skip to content

.loc function failed #4442

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
goog opened this issue Aug 2, 2013 · 2 comments
Closed

.loc function failed #4442

goog opened this issue Aug 2, 2013 · 2 comments

Comments

@goog
Copy link

goog commented Aug 2, 2013

env: windows 7 64bit, pandas 0.12

In [106]: res
Out[106]:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 93705 entries, 13 to 93713
Columns: 3561 entries, 2) to 3561)
dtypes: float64(3561)


In [107]: res.loc[12]
Out[107]:
0
2)     3.362026
3)     1.574658
4)     1.905283
6)     2.069734
8)     4.777519
9)     4.316618
11)    2.231455
......

my res's index starts with 13, but the numeric index loc[12] has values.

@hayd
Copy link
Contributor

hayd commented Aug 2, 2013

You can check that with is_monotonic (the 13 to 93713 isn't the min and max, rather it's the first and last)

You can check whether they are in order:

df.index.is_monotonic

And check whether 12 is in the index (if it isn't, I think you've found a bug):

12 in df.index

Just to show simple example:

In [11]: df = pd.DataFrame([[1,2], [3, 4]], index=[1, 2])

In [12]: pd.concat([df]*100)[:-1]  # glue together 100 dfs but don't include last row of the final one
Out[12]:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 199 entries, 1 to 1
Data columns (total 2 columns):
0    199  non-null values
1    199  non-null values
dtypes: int64(2)

In [13]: pd.concat([df]*100)[:-1].index.is_monotonic
Out[13]: False

In [14]: 2 in pd.concat([df]*100)[:-1].index
Out[14]: True

@goog
Copy link
Author

goog commented Aug 2, 2013

yeah, ur right! I misunderstood the "Int64Index: 93705 entries, 13 to 93713", thanks very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants