Pivot table conversion generating value error in pands










0















I am fetching data from the table which contains



execution_time, type, status, process, sub_process, value 
2018-11-12 16:09:48.179547, backlog, started, p1, s1, 100
2018-11-12 16:09:48.179547, backlog, created, p1, s1, 1005
2018-11-12 16:09:48.179547, backlog, started, p2, s1, 500
2018-11-12 16:09:48.179547, V1, created, p1, s1, 10
2018-11-12 16:09:48.179547, V2, created, p1, s1, 15
2018-11-12 16:09:48.179547, backlog, started, p3, s1, 0
2018-11-12 16:09:48.179547, backlog, started, p4, s1, 45
2018-11-12 16:09:48.179547, V1, started, p4, s1, 400


I want to pivot this data such that it should be like this:



status, process, sub_process, backlog, V1, V2



(backlog, V1 and V2 should contain corresponding values if exists)
Here is my code. I am getting error as




pivot_table() got multiple values for argument 'values'




sql = "select * from temp.data_table"
cursor.execute(sql)
results = cursor.fetchall()
df = pd.DataFrame(results)
df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')









share|improve this question




























    0















    I am fetching data from the table which contains



    execution_time, type, status, process, sub_process, value 
    2018-11-12 16:09:48.179547, backlog, started, p1, s1, 100
    2018-11-12 16:09:48.179547, backlog, created, p1, s1, 1005
    2018-11-12 16:09:48.179547, backlog, started, p2, s1, 500
    2018-11-12 16:09:48.179547, V1, created, p1, s1, 10
    2018-11-12 16:09:48.179547, V2, created, p1, s1, 15
    2018-11-12 16:09:48.179547, backlog, started, p3, s1, 0
    2018-11-12 16:09:48.179547, backlog, started, p4, s1, 45
    2018-11-12 16:09:48.179547, V1, started, p4, s1, 400


    I want to pivot this data such that it should be like this:



    status, process, sub_process, backlog, V1, V2



    (backlog, V1 and V2 should contain corresponding values if exists)
    Here is my code. I am getting error as




    pivot_table() got multiple values for argument 'values'




    sql = "select * from temp.data_table"
    cursor.execute(sql)
    results = cursor.fetchall()
    df = pd.DataFrame(results)
    df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')









    share|improve this question


























      0












      0








      0








      I am fetching data from the table which contains



      execution_time, type, status, process, sub_process, value 
      2018-11-12 16:09:48.179547, backlog, started, p1, s1, 100
      2018-11-12 16:09:48.179547, backlog, created, p1, s1, 1005
      2018-11-12 16:09:48.179547, backlog, started, p2, s1, 500
      2018-11-12 16:09:48.179547, V1, created, p1, s1, 10
      2018-11-12 16:09:48.179547, V2, created, p1, s1, 15
      2018-11-12 16:09:48.179547, backlog, started, p3, s1, 0
      2018-11-12 16:09:48.179547, backlog, started, p4, s1, 45
      2018-11-12 16:09:48.179547, V1, started, p4, s1, 400


      I want to pivot this data such that it should be like this:



      status, process, sub_process, backlog, V1, V2



      (backlog, V1 and V2 should contain corresponding values if exists)
      Here is my code. I am getting error as




      pivot_table() got multiple values for argument 'values'




      sql = "select * from temp.data_table"
      cursor.execute(sql)
      results = cursor.fetchall()
      df = pd.DataFrame(results)
      df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')









      share|improve this question
















      I am fetching data from the table which contains



      execution_time, type, status, process, sub_process, value 
      2018-11-12 16:09:48.179547, backlog, started, p1, s1, 100
      2018-11-12 16:09:48.179547, backlog, created, p1, s1, 1005
      2018-11-12 16:09:48.179547, backlog, started, p2, s1, 500
      2018-11-12 16:09:48.179547, V1, created, p1, s1, 10
      2018-11-12 16:09:48.179547, V2, created, p1, s1, 15
      2018-11-12 16:09:48.179547, backlog, started, p3, s1, 0
      2018-11-12 16:09:48.179547, backlog, started, p4, s1, 45
      2018-11-12 16:09:48.179547, V1, started, p4, s1, 400


      I want to pivot this data such that it should be like this:



      status, process, sub_process, backlog, V1, V2



      (backlog, V1 and V2 should contain corresponding values if exists)
      Here is my code. I am getting error as




      pivot_table() got multiple values for argument 'values'




      sql = "select * from temp.data_table"
      cursor.execute(sql)
      results = cursor.fetchall()
      df = pd.DataFrame(results)
      df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')






      python pandas cursor pivot






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 3:45









      Aqueous Carlos

      338314




      338314










      asked Nov 13 '18 at 1:55









      Madhura MhatreMadhura Mhatre

      43110




      43110






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Using (remove df in pivot_table )



          df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
          Out[85]:
          type V1 V2 backlog
          status process sub_process
          created p1 s1 10.0 15.0 1005.0
          started p1 s1 NaN NaN 100.0
          p2 s1 NaN NaN 500.0
          p3 s1 NaN NaN 0.0
          p4 s1 400.0 NaN 45.0


          Or pd.pivot_table



          pd.pivot_table(df,index=['status','process','sub_process'],columns='type',values=['value'], aggfunc = 'sum')
          Out[86]:
          value
          type V1 V2 backlog
          status process sub_process
          created p1 s1 10.0 15.0 1005.0
          started p1 s1 NaN NaN 100.0
          p2 s1 NaN NaN 500.0
          p3 s1 NaN NaN 0.0
          p4 s1 400.0 NaN 45.0





          share|improve this answer























          • hey @W-B I removed df but I am getting error as "KeyError: 'value'"

            – Madhura Mhatre
            Nov 13 '18 at 3:21











          • @MadhuraMhatre check you df columns by df.columns , i think you have white space there

            – W-B
            Nov 13 '18 at 3:22











          • This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')

            – Madhura Mhatre
            Nov 13 '18 at 3:28











          • @MadhuraMhatre runing fine on my side .

            – W-B
            Nov 13 '18 at 3:31











          • Thats interesting I still get that "KeyError: 'value'"

            – Madhura Mhatre
            Nov 13 '18 at 3:46











          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%2f53272669%2fpivot-table-conversion-generating-value-error-in-pands%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









          0














          Using (remove df in pivot_table )



          df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
          Out[85]:
          type V1 V2 backlog
          status process sub_process
          created p1 s1 10.0 15.0 1005.0
          started p1 s1 NaN NaN 100.0
          p2 s1 NaN NaN 500.0
          p3 s1 NaN NaN 0.0
          p4 s1 400.0 NaN 45.0


          Or pd.pivot_table



          pd.pivot_table(df,index=['status','process','sub_process'],columns='type',values=['value'], aggfunc = 'sum')
          Out[86]:
          value
          type V1 V2 backlog
          status process sub_process
          created p1 s1 10.0 15.0 1005.0
          started p1 s1 NaN NaN 100.0
          p2 s1 NaN NaN 500.0
          p3 s1 NaN NaN 0.0
          p4 s1 400.0 NaN 45.0





          share|improve this answer























          • hey @W-B I removed df but I am getting error as "KeyError: 'value'"

            – Madhura Mhatre
            Nov 13 '18 at 3:21











          • @MadhuraMhatre check you df columns by df.columns , i think you have white space there

            – W-B
            Nov 13 '18 at 3:22











          • This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')

            – Madhura Mhatre
            Nov 13 '18 at 3:28











          • @MadhuraMhatre runing fine on my side .

            – W-B
            Nov 13 '18 at 3:31











          • Thats interesting I still get that "KeyError: 'value'"

            – Madhura Mhatre
            Nov 13 '18 at 3:46
















          0














          Using (remove df in pivot_table )



          df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
          Out[85]:
          type V1 V2 backlog
          status process sub_process
          created p1 s1 10.0 15.0 1005.0
          started p1 s1 NaN NaN 100.0
          p2 s1 NaN NaN 500.0
          p3 s1 NaN NaN 0.0
          p4 s1 400.0 NaN 45.0


          Or pd.pivot_table



          pd.pivot_table(df,index=['status','process','sub_process'],columns='type',values=['value'], aggfunc = 'sum')
          Out[86]:
          value
          type V1 V2 backlog
          status process sub_process
          created p1 s1 10.0 15.0 1005.0
          started p1 s1 NaN NaN 100.0
          p2 s1 NaN NaN 500.0
          p3 s1 NaN NaN 0.0
          p4 s1 400.0 NaN 45.0





          share|improve this answer























          • hey @W-B I removed df but I am getting error as "KeyError: 'value'"

            – Madhura Mhatre
            Nov 13 '18 at 3:21











          • @MadhuraMhatre check you df columns by df.columns , i think you have white space there

            – W-B
            Nov 13 '18 at 3:22











          • This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')

            – Madhura Mhatre
            Nov 13 '18 at 3:28











          • @MadhuraMhatre runing fine on my side .

            – W-B
            Nov 13 '18 at 3:31











          • Thats interesting I still get that "KeyError: 'value'"

            – Madhura Mhatre
            Nov 13 '18 at 3:46














          0












          0








          0







          Using (remove df in pivot_table )



          df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
          Out[85]:
          type V1 V2 backlog
          status process sub_process
          created p1 s1 10.0 15.0 1005.0
          started p1 s1 NaN NaN 100.0
          p2 s1 NaN NaN 500.0
          p3 s1 NaN NaN 0.0
          p4 s1 400.0 NaN 45.0


          Or pd.pivot_table



          pd.pivot_table(df,index=['status','process','sub_process'],columns='type',values=['value'], aggfunc = 'sum')
          Out[86]:
          value
          type V1 V2 backlog
          status process sub_process
          created p1 s1 10.0 15.0 1005.0
          started p1 s1 NaN NaN 100.0
          p2 s1 NaN NaN 500.0
          p3 s1 NaN NaN 0.0
          p4 s1 400.0 NaN 45.0





          share|improve this answer













          Using (remove df in pivot_table )



          df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
          Out[85]:
          type V1 V2 backlog
          status process sub_process
          created p1 s1 10.0 15.0 1005.0
          started p1 s1 NaN NaN 100.0
          p2 s1 NaN NaN 500.0
          p3 s1 NaN NaN 0.0
          p4 s1 400.0 NaN 45.0


          Or pd.pivot_table



          pd.pivot_table(df,index=['status','process','sub_process'],columns='type',values=['value'], aggfunc = 'sum')
          Out[86]:
          value
          type V1 V2 backlog
          status process sub_process
          created p1 s1 10.0 15.0 1005.0
          started p1 s1 NaN NaN 100.0
          p2 s1 NaN NaN 500.0
          p3 s1 NaN NaN 0.0
          p4 s1 400.0 NaN 45.0






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 2:21









          W-BW-B

          108k83265




          108k83265












          • hey @W-B I removed df but I am getting error as "KeyError: 'value'"

            – Madhura Mhatre
            Nov 13 '18 at 3:21











          • @MadhuraMhatre check you df columns by df.columns , i think you have white space there

            – W-B
            Nov 13 '18 at 3:22











          • This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')

            – Madhura Mhatre
            Nov 13 '18 at 3:28











          • @MadhuraMhatre runing fine on my side .

            – W-B
            Nov 13 '18 at 3:31











          • Thats interesting I still get that "KeyError: 'value'"

            – Madhura Mhatre
            Nov 13 '18 at 3:46


















          • hey @W-B I removed df but I am getting error as "KeyError: 'value'"

            – Madhura Mhatre
            Nov 13 '18 at 3:21











          • @MadhuraMhatre check you df columns by df.columns , i think you have white space there

            – W-B
            Nov 13 '18 at 3:22











          • This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')

            – Madhura Mhatre
            Nov 13 '18 at 3:28











          • @MadhuraMhatre runing fine on my side .

            – W-B
            Nov 13 '18 at 3:31











          • Thats interesting I still get that "KeyError: 'value'"

            – Madhura Mhatre
            Nov 13 '18 at 3:46

















          hey @W-B I removed df but I am getting error as "KeyError: 'value'"

          – Madhura Mhatre
          Nov 13 '18 at 3:21





          hey @W-B I removed df but I am getting error as "KeyError: 'value'"

          – Madhura Mhatre
          Nov 13 '18 at 3:21













          @MadhuraMhatre check you df columns by df.columns , i think you have white space there

          – W-B
          Nov 13 '18 at 3:22





          @MadhuraMhatre check you df columns by df.columns , i think you have white space there

          – W-B
          Nov 13 '18 at 3:22













          This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')

          – Madhura Mhatre
          Nov 13 '18 at 3:28





          This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')

          – Madhura Mhatre
          Nov 13 '18 at 3:28













          @MadhuraMhatre runing fine on my side .

          – W-B
          Nov 13 '18 at 3:31





          @MadhuraMhatre runing fine on my side .

          – W-B
          Nov 13 '18 at 3:31













          Thats interesting I still get that "KeyError: 'value'"

          – Madhura Mhatre
          Nov 13 '18 at 3:46






          Thats interesting I still get that "KeyError: 'value'"

          – Madhura Mhatre
          Nov 13 '18 at 3:46


















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272669%2fpivot-table-conversion-generating-value-error-in-pands%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

          How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

          Syphilis

          Darth Vader #20