pandas.core.indexing.IndexingError: Too many indexers











up vote
2
down vote

favorite












I want to extract electricity consumption for Site 2



>>> df4 = pd.read_excel(xls, 'Elec Monthly Cons')
>>> df4
Site Unnamed: 1 2014-01-01 00:00:00 2014-02-01 00:00:00 2014-03-01 00:00:00 ... 2017-08-01 00:00:00 2017-09-01 00:00:00 2017-10-01 00:00:00 2017-11-01 00:00:00 2017-12-01 00:00:00
0 Site Profile JAN 2014 FEB 2014 MAR 2014 ... AUG 2017 SEP 2017 OCT 2017 NOV 2017 DEC 2017
1 Site 1 NHH 10344 NaN NaN ... NaN NaN NaN NaN NaN
2 Site 2 HH 258351 229513 239379 ... NaN NaN NaN NaN NaN


type



type(df4)
<class 'pandas.core.frame.DataFrame'>


My goal is to take out the numerical value but I do not know how to set the index properly. What I have tried so far does not work at all.



df1 = df.loc[idx[:,1:2],:]


But



    raise IndexingError('Too many indexers')
pandas.core.indexing.IndexingError: Too many indexers


It seems that I do not understand indexing. Does the series type play any role?



df.head
<bound method NDFrame.head of Site Site 2
Unnamed: 1 HH


EDIT



print (df.index)
Index([ 'Site', 'Unnamed: 1', 2014-01-01 00:00:00,
2014-02-01 00:00:00, 2014-03-01 00:00:00, 2014-04-01 00:00:00,
2014-05-01 00:00:00, 2014-06-01 00:00:00, 2014-07-01 00:00:00,


How to solve this?










share|improve this question




























    up vote
    2
    down vote

    favorite












    I want to extract electricity consumption for Site 2



    >>> df4 = pd.read_excel(xls, 'Elec Monthly Cons')
    >>> df4
    Site Unnamed: 1 2014-01-01 00:00:00 2014-02-01 00:00:00 2014-03-01 00:00:00 ... 2017-08-01 00:00:00 2017-09-01 00:00:00 2017-10-01 00:00:00 2017-11-01 00:00:00 2017-12-01 00:00:00
    0 Site Profile JAN 2014 FEB 2014 MAR 2014 ... AUG 2017 SEP 2017 OCT 2017 NOV 2017 DEC 2017
    1 Site 1 NHH 10344 NaN NaN ... NaN NaN NaN NaN NaN
    2 Site 2 HH 258351 229513 239379 ... NaN NaN NaN NaN NaN


    type



    type(df4)
    <class 'pandas.core.frame.DataFrame'>


    My goal is to take out the numerical value but I do not know how to set the index properly. What I have tried so far does not work at all.



    df1 = df.loc[idx[:,1:2],:]


    But



        raise IndexingError('Too many indexers')
    pandas.core.indexing.IndexingError: Too many indexers


    It seems that I do not understand indexing. Does the series type play any role?



    df.head
    <bound method NDFrame.head of Site Site 2
    Unnamed: 1 HH


    EDIT



    print (df.index)
    Index([ 'Site', 'Unnamed: 1', 2014-01-01 00:00:00,
    2014-02-01 00:00:00, 2014-03-01 00:00:00, 2014-04-01 00:00:00,
    2014-05-01 00:00:00, 2014-06-01 00:00:00, 2014-07-01 00:00:00,


    How to solve this?










    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I want to extract electricity consumption for Site 2



      >>> df4 = pd.read_excel(xls, 'Elec Monthly Cons')
      >>> df4
      Site Unnamed: 1 2014-01-01 00:00:00 2014-02-01 00:00:00 2014-03-01 00:00:00 ... 2017-08-01 00:00:00 2017-09-01 00:00:00 2017-10-01 00:00:00 2017-11-01 00:00:00 2017-12-01 00:00:00
      0 Site Profile JAN 2014 FEB 2014 MAR 2014 ... AUG 2017 SEP 2017 OCT 2017 NOV 2017 DEC 2017
      1 Site 1 NHH 10344 NaN NaN ... NaN NaN NaN NaN NaN
      2 Site 2 HH 258351 229513 239379 ... NaN NaN NaN NaN NaN


      type



      type(df4)
      <class 'pandas.core.frame.DataFrame'>


      My goal is to take out the numerical value but I do not know how to set the index properly. What I have tried so far does not work at all.



      df1 = df.loc[idx[:,1:2],:]


      But



          raise IndexingError('Too many indexers')
      pandas.core.indexing.IndexingError: Too many indexers


      It seems that I do not understand indexing. Does the series type play any role?



      df.head
      <bound method NDFrame.head of Site Site 2
      Unnamed: 1 HH


      EDIT



      print (df.index)
      Index([ 'Site', 'Unnamed: 1', 2014-01-01 00:00:00,
      2014-02-01 00:00:00, 2014-03-01 00:00:00, 2014-04-01 00:00:00,
      2014-05-01 00:00:00, 2014-06-01 00:00:00, 2014-07-01 00:00:00,


      How to solve this?










      share|improve this question















      I want to extract electricity consumption for Site 2



      >>> df4 = pd.read_excel(xls, 'Elec Monthly Cons')
      >>> df4
      Site Unnamed: 1 2014-01-01 00:00:00 2014-02-01 00:00:00 2014-03-01 00:00:00 ... 2017-08-01 00:00:00 2017-09-01 00:00:00 2017-10-01 00:00:00 2017-11-01 00:00:00 2017-12-01 00:00:00
      0 Site Profile JAN 2014 FEB 2014 MAR 2014 ... AUG 2017 SEP 2017 OCT 2017 NOV 2017 DEC 2017
      1 Site 1 NHH 10344 NaN NaN ... NaN NaN NaN NaN NaN
      2 Site 2 HH 258351 229513 239379 ... NaN NaN NaN NaN NaN


      type



      type(df4)
      <class 'pandas.core.frame.DataFrame'>


      My goal is to take out the numerical value but I do not know how to set the index properly. What I have tried so far does not work at all.



      df1 = df.loc[idx[:,1:2],:]


      But



          raise IndexingError('Too many indexers')
      pandas.core.indexing.IndexingError: Too many indexers


      It seems that I do not understand indexing. Does the series type play any role?



      df.head
      <bound method NDFrame.head of Site Site 2
      Unnamed: 1 HH


      EDIT



      print (df.index)
      Index([ 'Site', 'Unnamed: 1', 2014-01-01 00:00:00,
      2014-02-01 00:00:00, 2014-03-01 00:00:00, 2014-04-01 00:00:00,
      2014-05-01 00:00:00, 2014-06-01 00:00:00, 2014-07-01 00:00:00,


      How to solve this?







      python pandas






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 at 8:54

























      asked Nov 21 at 8:42









      MikiBelavista

      7801915




      7801915
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          In my opinion is necessary remove :, because it means select all columns, but Series have no column.



          Also it seems no MultiIndex, so then need:



          df1 = df.iloc[1:2]


          There is problem first 2 rows are headers, so for MultiIndex DataFrame need:



          df4 = pd.read_excel(xls, 'Elec Monthly Cons', header=[0,1], index_col=[0,1])


          And then for select use:



          idx = pd.IndexSlice
          df1 = df.loc[:, idx[:,'FEB 2014':'MAR 2014']]





          share|improve this answer























          • No,again the same.
            – MikiBelavista
            Nov 21 at 8:45










          • Please,take a look now!
            – MikiBelavista
            Nov 21 at 8:46










          • What is print (df.index) ?
            – jezrael
            Nov 21 at 8:46










          • @MikiBelavista - How is created DataFrame?
            – jezrael
            Nov 21 at 8:51










          • I have read xls into pandas then ,I have extracted the second row df4.iloc[2]
            – MikiBelavista
            Nov 21 at 8:55











          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',
          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%2f53408148%2fpandas-core-indexing-indexingerror-too-many-indexers%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          In my opinion is necessary remove :, because it means select all columns, but Series have no column.



          Also it seems no MultiIndex, so then need:



          df1 = df.iloc[1:2]


          There is problem first 2 rows are headers, so for MultiIndex DataFrame need:



          df4 = pd.read_excel(xls, 'Elec Monthly Cons', header=[0,1], index_col=[0,1])


          And then for select use:



          idx = pd.IndexSlice
          df1 = df.loc[:, idx[:,'FEB 2014':'MAR 2014']]





          share|improve this answer























          • No,again the same.
            – MikiBelavista
            Nov 21 at 8:45










          • Please,take a look now!
            – MikiBelavista
            Nov 21 at 8:46










          • What is print (df.index) ?
            – jezrael
            Nov 21 at 8:46










          • @MikiBelavista - How is created DataFrame?
            – jezrael
            Nov 21 at 8:51










          • I have read xls into pandas then ,I have extracted the second row df4.iloc[2]
            – MikiBelavista
            Nov 21 at 8:55















          up vote
          1
          down vote



          accepted










          In my opinion is necessary remove :, because it means select all columns, but Series have no column.



          Also it seems no MultiIndex, so then need:



          df1 = df.iloc[1:2]


          There is problem first 2 rows are headers, so for MultiIndex DataFrame need:



          df4 = pd.read_excel(xls, 'Elec Monthly Cons', header=[0,1], index_col=[0,1])


          And then for select use:



          idx = pd.IndexSlice
          df1 = df.loc[:, idx[:,'FEB 2014':'MAR 2014']]





          share|improve this answer























          • No,again the same.
            – MikiBelavista
            Nov 21 at 8:45










          • Please,take a look now!
            – MikiBelavista
            Nov 21 at 8:46










          • What is print (df.index) ?
            – jezrael
            Nov 21 at 8:46










          • @MikiBelavista - How is created DataFrame?
            – jezrael
            Nov 21 at 8:51










          • I have read xls into pandas then ,I have extracted the second row df4.iloc[2]
            – MikiBelavista
            Nov 21 at 8:55













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          In my opinion is necessary remove :, because it means select all columns, but Series have no column.



          Also it seems no MultiIndex, so then need:



          df1 = df.iloc[1:2]


          There is problem first 2 rows are headers, so for MultiIndex DataFrame need:



          df4 = pd.read_excel(xls, 'Elec Monthly Cons', header=[0,1], index_col=[0,1])


          And then for select use:



          idx = pd.IndexSlice
          df1 = df.loc[:, idx[:,'FEB 2014':'MAR 2014']]





          share|improve this answer














          In my opinion is necessary remove :, because it means select all columns, but Series have no column.



          Also it seems no MultiIndex, so then need:



          df1 = df.iloc[1:2]


          There is problem first 2 rows are headers, so for MultiIndex DataFrame need:



          df4 = pd.read_excel(xls, 'Elec Monthly Cons', header=[0,1], index_col=[0,1])


          And then for select use:



          idx = pd.IndexSlice
          df1 = df.loc[:, idx[:,'FEB 2014':'MAR 2014']]






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 at 8:55

























          answered Nov 21 at 8:43









          jezrael

          310k21246321




          310k21246321












          • No,again the same.
            – MikiBelavista
            Nov 21 at 8:45










          • Please,take a look now!
            – MikiBelavista
            Nov 21 at 8:46










          • What is print (df.index) ?
            – jezrael
            Nov 21 at 8:46










          • @MikiBelavista - How is created DataFrame?
            – jezrael
            Nov 21 at 8:51










          • I have read xls into pandas then ,I have extracted the second row df4.iloc[2]
            – MikiBelavista
            Nov 21 at 8:55


















          • No,again the same.
            – MikiBelavista
            Nov 21 at 8:45










          • Please,take a look now!
            – MikiBelavista
            Nov 21 at 8:46










          • What is print (df.index) ?
            – jezrael
            Nov 21 at 8:46










          • @MikiBelavista - How is created DataFrame?
            – jezrael
            Nov 21 at 8:51










          • I have read xls into pandas then ,I have extracted the second row df4.iloc[2]
            – MikiBelavista
            Nov 21 at 8:55
















          No,again the same.
          – MikiBelavista
          Nov 21 at 8:45




          No,again the same.
          – MikiBelavista
          Nov 21 at 8:45












          Please,take a look now!
          – MikiBelavista
          Nov 21 at 8:46




          Please,take a look now!
          – MikiBelavista
          Nov 21 at 8:46












          What is print (df.index) ?
          – jezrael
          Nov 21 at 8:46




          What is print (df.index) ?
          – jezrael
          Nov 21 at 8:46












          @MikiBelavista - How is created DataFrame?
          – jezrael
          Nov 21 at 8:51




          @MikiBelavista - How is created DataFrame?
          – jezrael
          Nov 21 at 8:51












          I have read xls into pandas then ,I have extracted the second row df4.iloc[2]
          – MikiBelavista
          Nov 21 at 8:55




          I have read xls into pandas then ,I have extracted the second row df4.iloc[2]
          – MikiBelavista
          Nov 21 at 8:55


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408148%2fpandas-core-indexing-indexingerror-too-many-indexers%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

          Berounka

          Sphinx de Gizeh

          Different font size/position of beamer's navigation symbols template's content depending on regular/plain...