Skip to content
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

Passing MultiIndex to loc leads to keyError #1610

Closed
0x-Johnson opened this issue Jun 16, 2020 · 2 comments · Fixed by #1789
Closed

Passing MultiIndex to loc leads to keyError #1610

0x-Johnson opened this issue Jun 16, 2020 · 2 comments · Fixed by #1789
Assignees
Labels
bug 🦗 Something isn't working
Milestone

Comments

@0x-Johnson
Copy link

DataFrame result has colums, ['code_jq', 'time', 'factor', 'close'].

result = result.set_index(['code_jq', 'time']).sort_index(ascending=False);
cut = result.groupby(['code_jq'])['factor'].apply(lambda x: len(x) >= total_days - 10);
result = result.loc[cut[cut].index]

When the program runs to this line of code, result = result.loc[cut[cut].index] ,it shows keyerror that means dataframe can't find keys.

Is anyone know why and how to solve it?

@0x-Johnson 0x-Johnson added the question ❓ Questions about Modin label Jun 16, 2020
@devin-petersohn devin-petersohn added bug 🦗 Something isn't working and removed question ❓ Questions about Modin labels Jun 16, 2020
@devin-petersohn
Copy link
Collaborator

Hi @513090336, thanks for the report. I was able to reproduce what you're seeing, it is an issue with loc and MultiIndex. We will get this fixed.

As a temporary workaround, you can use this code:

result = result.set_index(['code_jq', 'time']).sort_index(ascending=False);
cut = result.groupby(['code_jq'])['factor'].apply(lambda x: len(x) >= total_days - 10)
indexer = cut.index.get_indexer_for(cut[cut].index)
result = result.iloc[indexer]

@devin-petersohn devin-petersohn added this to the 0.7.4 milestone Jun 16, 2020
@devin-petersohn devin-petersohn changed the title loc leads to keyError Passing MultiIndex to loc leads to keyError Jun 16, 2020
@0x-Johnson
Copy link
Author

Thank you!you helps me a lot.

@devin-petersohn devin-petersohn self-assigned this Jul 23, 2020
devin-petersohn added a commit to devin-petersohn/modin that referenced this issue Jul 23, 2020
Signed-off-by: Devin Petersohn <devin.petersohn@gmail.com>
aregm pushed a commit that referenced this issue Jul 24, 2020
Signed-off-by: Devin Petersohn <devin.petersohn@gmail.com>
aregm pushed a commit to aregm/modin that referenced this issue Sep 16, 2020
…er (modin-project#1789)

Signed-off-by: Devin Petersohn <devin.petersohn@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🦗 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants