SARIMAX predicted_mean output












0














I am using SARIMAX to do a forecast model and i would like to add column titles to the output but i'm having trouble. I can work around it by doing .to_csv then reading it back in as a new dataframe before adding the labels but i'd like to be able to do it in one step rather than writing another file.



    mod = sm.tsa.statespace.SARIMAX(y,
order=(0, 1, 1),
seasonal_order=(0, 1, 1, 12),
enforce_stationarity=False,
enforce_invertibility=False)
results = mod.fit()
pred_uc = results.get_forecast(steps = 48)
pred_ci = pred_uc.conf_int()

forecast = pd.DataFrame(pred_uc.predicted_mean, columns = ['TIME', 'column_2'])


ValueError: Wrong number of items passed 1, placement implies 2



ValueError: Shape of passed values is (1, 48), indices imply (2, 48)










share|improve this question



























    0














    I am using SARIMAX to do a forecast model and i would like to add column titles to the output but i'm having trouble. I can work around it by doing .to_csv then reading it back in as a new dataframe before adding the labels but i'd like to be able to do it in one step rather than writing another file.



        mod = sm.tsa.statespace.SARIMAX(y,
    order=(0, 1, 1),
    seasonal_order=(0, 1, 1, 12),
    enforce_stationarity=False,
    enforce_invertibility=False)
    results = mod.fit()
    pred_uc = results.get_forecast(steps = 48)
    pred_ci = pred_uc.conf_int()

    forecast = pd.DataFrame(pred_uc.predicted_mean, columns = ['TIME', 'column_2'])


    ValueError: Wrong number of items passed 1, placement implies 2



    ValueError: Shape of passed values is (1, 48), indices imply (2, 48)










    share|improve this question

























      0












      0








      0







      I am using SARIMAX to do a forecast model and i would like to add column titles to the output but i'm having trouble. I can work around it by doing .to_csv then reading it back in as a new dataframe before adding the labels but i'd like to be able to do it in one step rather than writing another file.



          mod = sm.tsa.statespace.SARIMAX(y,
      order=(0, 1, 1),
      seasonal_order=(0, 1, 1, 12),
      enforce_stationarity=False,
      enforce_invertibility=False)
      results = mod.fit()
      pred_uc = results.get_forecast(steps = 48)
      pred_ci = pred_uc.conf_int()

      forecast = pd.DataFrame(pred_uc.predicted_mean, columns = ['TIME', 'column_2'])


      ValueError: Wrong number of items passed 1, placement implies 2



      ValueError: Shape of passed values is (1, 48), indices imply (2, 48)










      share|improve this question













      I am using SARIMAX to do a forecast model and i would like to add column titles to the output but i'm having trouble. I can work around it by doing .to_csv then reading it back in as a new dataframe before adding the labels but i'd like to be able to do it in one step rather than writing another file.



          mod = sm.tsa.statespace.SARIMAX(y,
      order=(0, 1, 1),
      seasonal_order=(0, 1, 1, 12),
      enforce_stationarity=False,
      enforce_invertibility=False)
      results = mod.fit()
      pred_uc = results.get_forecast(steps = 48)
      pred_ci = pred_uc.conf_int()

      forecast = pd.DataFrame(pred_uc.predicted_mean, columns = ['TIME', 'column_2'])


      ValueError: Wrong number of items passed 1, placement implies 2



      ValueError: Shape of passed values is (1, 48), indices imply (2, 48)







      python pandas statsmodels






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 23 '18 at 4:39









      Paul ClarkePaul Clarke

      83




      83
























          2 Answers
          2






          active

          oldest

          votes


















          0














          pred_uc.predicted_mean is a pandas Series object, associated with an index (e.g. a date index).



          You can convert it to a DataFrame, with e.g. pred_uc.predicted_mean.to_frame(), but it will still only have one column and an index.



          If for some reason you must have it in the form you showed, you could do e.g. the following:



          pred_uc.predicted_mean.to_frame('column_2').rename_axis('time').reset_index()


          which would give something like:



              time  column_2
          0 2009Q4 3.791093
          1 2010Q1 1.864600
          2 2010Q2 0.680030
          3 2010Q3 2.299168





          share|improve this answer





























            0














            After a bit of reading i ended up finding a solution that suited best because this is iterating and creating a new column for the results each time.



            compiled_df[column_2] = forecast[0]
            compiled_df.index.name = 'TIME'


            Thank you for your help






            share|improve this answer





















              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%2f53901235%2fsarimax-predicted-mean-output%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









              0














              pred_uc.predicted_mean is a pandas Series object, associated with an index (e.g. a date index).



              You can convert it to a DataFrame, with e.g. pred_uc.predicted_mean.to_frame(), but it will still only have one column and an index.



              If for some reason you must have it in the form you showed, you could do e.g. the following:



              pred_uc.predicted_mean.to_frame('column_2').rename_axis('time').reset_index()


              which would give something like:



                  time  column_2
              0 2009Q4 3.791093
              1 2010Q1 1.864600
              2 2010Q2 0.680030
              3 2010Q3 2.299168





              share|improve this answer


























                0














                pred_uc.predicted_mean is a pandas Series object, associated with an index (e.g. a date index).



                You can convert it to a DataFrame, with e.g. pred_uc.predicted_mean.to_frame(), but it will still only have one column and an index.



                If for some reason you must have it in the form you showed, you could do e.g. the following:



                pred_uc.predicted_mean.to_frame('column_2').rename_axis('time').reset_index()


                which would give something like:



                    time  column_2
                0 2009Q4 3.791093
                1 2010Q1 1.864600
                2 2010Q2 0.680030
                3 2010Q3 2.299168





                share|improve this answer
























                  0












                  0








                  0






                  pred_uc.predicted_mean is a pandas Series object, associated with an index (e.g. a date index).



                  You can convert it to a DataFrame, with e.g. pred_uc.predicted_mean.to_frame(), but it will still only have one column and an index.



                  If for some reason you must have it in the form you showed, you could do e.g. the following:



                  pred_uc.predicted_mean.to_frame('column_2').rename_axis('time').reset_index()


                  which would give something like:



                      time  column_2
                  0 2009Q4 3.791093
                  1 2010Q1 1.864600
                  2 2010Q2 0.680030
                  3 2010Q3 2.299168





                  share|improve this answer












                  pred_uc.predicted_mean is a pandas Series object, associated with an index (e.g. a date index).



                  You can convert it to a DataFrame, with e.g. pred_uc.predicted_mean.to_frame(), but it will still only have one column and an index.



                  If for some reason you must have it in the form you showed, you could do e.g. the following:



                  pred_uc.predicted_mean.to_frame('column_2').rename_axis('time').reset_index()


                  which would give something like:



                      time  column_2
                  0 2009Q4 3.791093
                  1 2010Q1 1.864600
                  2 2010Q2 0.680030
                  3 2010Q3 2.299168






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 27 '18 at 0:30









                  cfultoncfulton

                  26613




                  26613

























                      0














                      After a bit of reading i ended up finding a solution that suited best because this is iterating and creating a new column for the results each time.



                      compiled_df[column_2] = forecast[0]
                      compiled_df.index.name = 'TIME'


                      Thank you for your help






                      share|improve this answer


























                        0














                        After a bit of reading i ended up finding a solution that suited best because this is iterating and creating a new column for the results each time.



                        compiled_df[column_2] = forecast[0]
                        compiled_df.index.name = 'TIME'


                        Thank you for your help






                        share|improve this answer
























                          0












                          0








                          0






                          After a bit of reading i ended up finding a solution that suited best because this is iterating and creating a new column for the results each time.



                          compiled_df[column_2] = forecast[0]
                          compiled_df.index.name = 'TIME'


                          Thank you for your help






                          share|improve this answer












                          After a bit of reading i ended up finding a solution that suited best because this is iterating and creating a new column for the results each time.



                          compiled_df[column_2] = forecast[0]
                          compiled_df.index.name = 'TIME'


                          Thank you for your help







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 28 '18 at 6:01









                          Paul ClarkePaul Clarke

                          83




                          83






























                              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%2f53901235%2fsarimax-predicted-mean-output%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

                              Monofisismo

                              Angular Downloading a file using contenturl with Basic Authentication

                              Olmecas