pandas sort_index (sometimes?) throws error : IndexError: pop index out of range
up vote
0
down vote
favorite
I have a dataframe with 3 indexes, and i am trying to sort them. Unfortunately depending on the order that I try and sort the indexes I sometimes get the following error:
Traceback (most recent call last):
File "<ipython-input-30-30a4bb212256>", line 1, in <module>
df_srmc_lrmc.sort_index(axis='index', level=['Station_Type', 'Generator','Year'], inplace=True)
File "E:Python35WinPython-64bit-3.5.4.0Qt5python-3.5.4.amd64libsite-packagespandascoreframe.py", line 3236, in sort_index
sort_remaining=sort_remaining)
File "E:Python35WinPython-64bit-3.5.4.0Qt5python-3.5.4.amd64libsite-packagespandascoreindexesmulti.py", line 1714, in sortlevel
primary = tuple(labels.pop(lev - i) for i, lev in enumerate(level))
File "E:Python35WinPython-64bit-3.5.4.0Qt5python-3.5.4.amd64libsite-packagespandascoreindexesmulti.py", line 1714, in <genexpr>
primary = tuple(labels.pop(lev - i) for i, lev in enumerate(level))
IndexError: pop index out of range
Looking at my dataframe, you can see the following indexes:
df_srmc_lrmc.index.names
Out[32]: FrozenList(['Year', 'Generator', 'Station_Type'])
The following sort commands work:
df_srmc_lrmc.sort_index(axis='index', level=['Generator','Year','Station_Type'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Year','Station_Type', 'Generator'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Year','Generator','Station_Type'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Station_Type', 'Year','Generator'], inplace=True)
But the following don't, they throw the error mentioned above:
df_srmc_lrmc.sort_index(axis='index', level=['Generator','Station_Type','Year'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Station_Type', 'Generator','Year'], inplace=True)
As I am sure you have guessed, I am wanting one of the sort orders that doesn't work :(
My pandas version info:
pd.__version__
Out[34]: '0.20.3'
Can someone tell me what is going on, or what I am doing wrong? I am quite new to Python so the more handholding the better.
Thanks
python pandas dataframe
add a comment |
up vote
0
down vote
favorite
I have a dataframe with 3 indexes, and i am trying to sort them. Unfortunately depending on the order that I try and sort the indexes I sometimes get the following error:
Traceback (most recent call last):
File "<ipython-input-30-30a4bb212256>", line 1, in <module>
df_srmc_lrmc.sort_index(axis='index', level=['Station_Type', 'Generator','Year'], inplace=True)
File "E:Python35WinPython-64bit-3.5.4.0Qt5python-3.5.4.amd64libsite-packagespandascoreframe.py", line 3236, in sort_index
sort_remaining=sort_remaining)
File "E:Python35WinPython-64bit-3.5.4.0Qt5python-3.5.4.amd64libsite-packagespandascoreindexesmulti.py", line 1714, in sortlevel
primary = tuple(labels.pop(lev - i) for i, lev in enumerate(level))
File "E:Python35WinPython-64bit-3.5.4.0Qt5python-3.5.4.amd64libsite-packagespandascoreindexesmulti.py", line 1714, in <genexpr>
primary = tuple(labels.pop(lev - i) for i, lev in enumerate(level))
IndexError: pop index out of range
Looking at my dataframe, you can see the following indexes:
df_srmc_lrmc.index.names
Out[32]: FrozenList(['Year', 'Generator', 'Station_Type'])
The following sort commands work:
df_srmc_lrmc.sort_index(axis='index', level=['Generator','Year','Station_Type'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Year','Station_Type', 'Generator'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Year','Generator','Station_Type'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Station_Type', 'Year','Generator'], inplace=True)
But the following don't, they throw the error mentioned above:
df_srmc_lrmc.sort_index(axis='index', level=['Generator','Station_Type','Year'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Station_Type', 'Generator','Year'], inplace=True)
As I am sure you have guessed, I am wanting one of the sort orders that doesn't work :(
My pandas version info:
pd.__version__
Out[34]: '0.20.3'
Can someone tell me what is going on, or what I am doing wrong? I am quite new to Python so the more handholding the better.
Thanks
python pandas dataframe
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a dataframe with 3 indexes, and i am trying to sort them. Unfortunately depending on the order that I try and sort the indexes I sometimes get the following error:
Traceback (most recent call last):
File "<ipython-input-30-30a4bb212256>", line 1, in <module>
df_srmc_lrmc.sort_index(axis='index', level=['Station_Type', 'Generator','Year'], inplace=True)
File "E:Python35WinPython-64bit-3.5.4.0Qt5python-3.5.4.amd64libsite-packagespandascoreframe.py", line 3236, in sort_index
sort_remaining=sort_remaining)
File "E:Python35WinPython-64bit-3.5.4.0Qt5python-3.5.4.amd64libsite-packagespandascoreindexesmulti.py", line 1714, in sortlevel
primary = tuple(labels.pop(lev - i) for i, lev in enumerate(level))
File "E:Python35WinPython-64bit-3.5.4.0Qt5python-3.5.4.amd64libsite-packagespandascoreindexesmulti.py", line 1714, in <genexpr>
primary = tuple(labels.pop(lev - i) for i, lev in enumerate(level))
IndexError: pop index out of range
Looking at my dataframe, you can see the following indexes:
df_srmc_lrmc.index.names
Out[32]: FrozenList(['Year', 'Generator', 'Station_Type'])
The following sort commands work:
df_srmc_lrmc.sort_index(axis='index', level=['Generator','Year','Station_Type'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Year','Station_Type', 'Generator'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Year','Generator','Station_Type'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Station_Type', 'Year','Generator'], inplace=True)
But the following don't, they throw the error mentioned above:
df_srmc_lrmc.sort_index(axis='index', level=['Generator','Station_Type','Year'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Station_Type', 'Generator','Year'], inplace=True)
As I am sure you have guessed, I am wanting one of the sort orders that doesn't work :(
My pandas version info:
pd.__version__
Out[34]: '0.20.3'
Can someone tell me what is going on, or what I am doing wrong? I am quite new to Python so the more handholding the better.
Thanks
python pandas dataframe
I have a dataframe with 3 indexes, and i am trying to sort them. Unfortunately depending on the order that I try and sort the indexes I sometimes get the following error:
Traceback (most recent call last):
File "<ipython-input-30-30a4bb212256>", line 1, in <module>
df_srmc_lrmc.sort_index(axis='index', level=['Station_Type', 'Generator','Year'], inplace=True)
File "E:Python35WinPython-64bit-3.5.4.0Qt5python-3.5.4.amd64libsite-packagespandascoreframe.py", line 3236, in sort_index
sort_remaining=sort_remaining)
File "E:Python35WinPython-64bit-3.5.4.0Qt5python-3.5.4.amd64libsite-packagespandascoreindexesmulti.py", line 1714, in sortlevel
primary = tuple(labels.pop(lev - i) for i, lev in enumerate(level))
File "E:Python35WinPython-64bit-3.5.4.0Qt5python-3.5.4.amd64libsite-packagespandascoreindexesmulti.py", line 1714, in <genexpr>
primary = tuple(labels.pop(lev - i) for i, lev in enumerate(level))
IndexError: pop index out of range
Looking at my dataframe, you can see the following indexes:
df_srmc_lrmc.index.names
Out[32]: FrozenList(['Year', 'Generator', 'Station_Type'])
The following sort commands work:
df_srmc_lrmc.sort_index(axis='index', level=['Generator','Year','Station_Type'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Year','Station_Type', 'Generator'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Year','Generator','Station_Type'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Station_Type', 'Year','Generator'], inplace=True)
But the following don't, they throw the error mentioned above:
df_srmc_lrmc.sort_index(axis='index', level=['Generator','Station_Type','Year'], inplace=True)
df_srmc_lrmc.sort_index(axis='index', level=['Station_Type', 'Generator','Year'], inplace=True)
As I am sure you have guessed, I am wanting one of the sort orders that doesn't work :(
My pandas version info:
pd.__version__
Out[34]: '0.20.3'
Can someone tell me what is going on, or what I am doing wrong? I am quite new to Python so the more handholding the better.
Thanks
python pandas dataframe
python pandas dataframe
asked Nov 21 at 22:02
Andrewfreestuff
337
337
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421081%2fpandas-sort-index-sometimes-throws-error-indexerror-pop-index-out-of-range%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown