SARIMAX predicted_mean output
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
add a comment |
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
add a comment |
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
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
python pandas statsmodels
asked Dec 23 '18 at 4:39
Paul ClarkePaul Clarke
83
83
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
add a comment |
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
add a comment |
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
});
}
});
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%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
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
add a comment |
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
add a comment |
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
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
answered Dec 27 '18 at 0:30
cfultoncfulton
26613
26613
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Dec 28 '18 at 6:01
Paul ClarkePaul Clarke
83
83
add a comment |
add a comment |
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%2f53901235%2fsarimax-predicted-mean-output%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