Pandas error with multidimensional key using .loc and a boolean












0














Been running into this same error for 2 weeks, even though the code worked before. Not sure if I updated pandas as part of another library install, and maybe something changed there. Currently on version 23.4. Expected outcome is returning just the row with that identifier value.



In [42]: df.head()

Out[43]:

index Identifier ...
0 51384710 ...
1 74838J10 ...
2 80589M10 ...
3 67104410 ...
4 50241310 ...

[5 rows x 14 columns]
In [43]: df.loc[df.Identifier.isin(['51384710'])].head()
Traceback (most recent call last):
File "C:anaconda3libsite-packagesIPythoncoreinteractiveshell.py", line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-44-a3dbf43451ef>", line 1, in <module>
df.loc[df.Identifier.isin(['51384710'])].head()
File "C:anaconda3libsite-packagespandascoreindexing.py", line 1478, in __getitem__
return self._getitem_axis(maybe_callable, axis=axis)
File "C:anaconda3libsite-packagespandascoreindexing.py", line 1899, in _getitem_axis
raise ValueError('Cannot index with multidimensional key')
**ValueError: Cannot index with multidimensional key**


Code Snippet










share|improve this question
























  • df.loc[df.Identifier.isin(['51384710'])].head() is working for me
    – nixon
    Nov 20 at 17:14
















0














Been running into this same error for 2 weeks, even though the code worked before. Not sure if I updated pandas as part of another library install, and maybe something changed there. Currently on version 23.4. Expected outcome is returning just the row with that identifier value.



In [42]: df.head()

Out[43]:

index Identifier ...
0 51384710 ...
1 74838J10 ...
2 80589M10 ...
3 67104410 ...
4 50241310 ...

[5 rows x 14 columns]
In [43]: df.loc[df.Identifier.isin(['51384710'])].head()
Traceback (most recent call last):
File "C:anaconda3libsite-packagesIPythoncoreinteractiveshell.py", line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-44-a3dbf43451ef>", line 1, in <module>
df.loc[df.Identifier.isin(['51384710'])].head()
File "C:anaconda3libsite-packagespandascoreindexing.py", line 1478, in __getitem__
return self._getitem_axis(maybe_callable, axis=axis)
File "C:anaconda3libsite-packagespandascoreindexing.py", line 1899, in _getitem_axis
raise ValueError('Cannot index with multidimensional key')
**ValueError: Cannot index with multidimensional key**


Code Snippet










share|improve this question
























  • df.loc[df.Identifier.isin(['51384710'])].head() is working for me
    – nixon
    Nov 20 at 17:14














0












0








0







Been running into this same error for 2 weeks, even though the code worked before. Not sure if I updated pandas as part of another library install, and maybe something changed there. Currently on version 23.4. Expected outcome is returning just the row with that identifier value.



In [42]: df.head()

Out[43]:

index Identifier ...
0 51384710 ...
1 74838J10 ...
2 80589M10 ...
3 67104410 ...
4 50241310 ...

[5 rows x 14 columns]
In [43]: df.loc[df.Identifier.isin(['51384710'])].head()
Traceback (most recent call last):
File "C:anaconda3libsite-packagesIPythoncoreinteractiveshell.py", line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-44-a3dbf43451ef>", line 1, in <module>
df.loc[df.Identifier.isin(['51384710'])].head()
File "C:anaconda3libsite-packagespandascoreindexing.py", line 1478, in __getitem__
return self._getitem_axis(maybe_callable, axis=axis)
File "C:anaconda3libsite-packagespandascoreindexing.py", line 1899, in _getitem_axis
raise ValueError('Cannot index with multidimensional key')
**ValueError: Cannot index with multidimensional key**


Code Snippet










share|improve this question















Been running into this same error for 2 weeks, even though the code worked before. Not sure if I updated pandas as part of another library install, and maybe something changed there. Currently on version 23.4. Expected outcome is returning just the row with that identifier value.



In [42]: df.head()

Out[43]:

index Identifier ...
0 51384710 ...
1 74838J10 ...
2 80589M10 ...
3 67104410 ...
4 50241310 ...

[5 rows x 14 columns]
In [43]: df.loc[df.Identifier.isin(['51384710'])].head()
Traceback (most recent call last):
File "C:anaconda3libsite-packagesIPythoncoreinteractiveshell.py", line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-44-a3dbf43451ef>", line 1, in <module>
df.loc[df.Identifier.isin(['51384710'])].head()
File "C:anaconda3libsite-packagespandascoreindexing.py", line 1478, in __getitem__
return self._getitem_axis(maybe_callable, axis=axis)
File "C:anaconda3libsite-packagespandascoreindexing.py", line 1899, in _getitem_axis
raise ValueError('Cannot index with multidimensional key')
**ValueError: Cannot index with multidimensional key**


Code Snippet







pandas conditional valueerror






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 17:17

























asked Nov 20 at 17:06









Bakes

113




113












  • df.loc[df.Identifier.isin(['51384710'])].head() is working for me
    – nixon
    Nov 20 at 17:14


















  • df.loc[df.Identifier.isin(['51384710'])].head() is working for me
    – nixon
    Nov 20 at 17:14
















df.loc[df.Identifier.isin(['51384710'])].head() is working for me
– nixon
Nov 20 at 17:14




df.loc[df.Identifier.isin(['51384710'])].head() is working for me
– nixon
Nov 20 at 17:14












2 Answers
2






active

oldest

votes


















1














Fixed it. I'd done df.columns = [column_list] where column_list = [...], which caused df to be treated as if it had a multiindex, even though there was only one level. removed the brackets from the df.columns assignment.






share|improve this answer





























    0














    Try changing



    df.loc[df.Identifier.isin(['51384710'])].head()


    to



    df[df.Identifier.isin(['51384710'])].head()





    share|improve this answer





















    • When I don't use .loc I get: index Identifier ... 0 51384710 ... 1 NaN ... 2 NaN ... 3 NaN ... 4 NaN ...
      – Bakes
      Nov 20 at 17:19













    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398022%2fpandas-error-with-multidimensional-key-using-loc-and-a-boolean%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Fixed it. I'd done df.columns = [column_list] where column_list = [...], which caused df to be treated as if it had a multiindex, even though there was only one level. removed the brackets from the df.columns assignment.






    share|improve this answer


























      1














      Fixed it. I'd done df.columns = [column_list] where column_list = [...], which caused df to be treated as if it had a multiindex, even though there was only one level. removed the brackets from the df.columns assignment.






      share|improve this answer
























        1












        1








        1






        Fixed it. I'd done df.columns = [column_list] where column_list = [...], which caused df to be treated as if it had a multiindex, even though there was only one level. removed the brackets from the df.columns assignment.






        share|improve this answer












        Fixed it. I'd done df.columns = [column_list] where column_list = [...], which caused df to be treated as if it had a multiindex, even though there was only one level. removed the brackets from the df.columns assignment.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 at 18:14









        Bakes

        113




        113

























            0














            Try changing



            df.loc[df.Identifier.isin(['51384710'])].head()


            to



            df[df.Identifier.isin(['51384710'])].head()





            share|improve this answer





















            • When I don't use .loc I get: index Identifier ... 0 51384710 ... 1 NaN ... 2 NaN ... 3 NaN ... 4 NaN ...
              – Bakes
              Nov 20 at 17:19


















            0














            Try changing



            df.loc[df.Identifier.isin(['51384710'])].head()


            to



            df[df.Identifier.isin(['51384710'])].head()





            share|improve this answer





















            • When I don't use .loc I get: index Identifier ... 0 51384710 ... 1 NaN ... 2 NaN ... 3 NaN ... 4 NaN ...
              – Bakes
              Nov 20 at 17:19
















            0












            0








            0






            Try changing



            df.loc[df.Identifier.isin(['51384710'])].head()


            to



            df[df.Identifier.isin(['51384710'])].head()





            share|improve this answer












            Try changing



            df.loc[df.Identifier.isin(['51384710'])].head()


            to



            df[df.Identifier.isin(['51384710'])].head()






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 20 at 17:12









            Peter Leimbigler

            3,7041415




            3,7041415












            • When I don't use .loc I get: index Identifier ... 0 51384710 ... 1 NaN ... 2 NaN ... 3 NaN ... 4 NaN ...
              – Bakes
              Nov 20 at 17:19




















            • When I don't use .loc I get: index Identifier ... 0 51384710 ... 1 NaN ... 2 NaN ... 3 NaN ... 4 NaN ...
              – Bakes
              Nov 20 at 17:19


















            When I don't use .loc I get: index Identifier ... 0 51384710 ... 1 NaN ... 2 NaN ... 3 NaN ... 4 NaN ...
            – Bakes
            Nov 20 at 17:19






            When I don't use .loc I get: index Identifier ... 0 51384710 ... 1 NaN ... 2 NaN ... 3 NaN ... 4 NaN ...
            – Bakes
            Nov 20 at 17:19




















            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398022%2fpandas-error-with-multidimensional-key-using-loc-and-a-boolean%23new-answer', 'question_page');
            }
            );

            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







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen