P-value normal test for multiple rows
I got the following simple code to calculate normality over an array:
import pandas as pd
df = pd.read_excel("directoryfile.xlsx")
import numpy as np
x=df.iloc[:,1:].values.flatten()
import scipy.stats as stats
from scipy.stats import normaltest
stats.normaltest(x,axis=None)
This gives me nicely a p-value and a statistic.
The only thing I want right now is to:
Add 2 columns in the file with this p value and statistic and if i have multiple rows, do it for all the rows (calculate p value & statistic for each row and add 2 columns with these values in it).
Can someone help?
python-3.x pandas statistics
add a comment |
I got the following simple code to calculate normality over an array:
import pandas as pd
df = pd.read_excel("directoryfile.xlsx")
import numpy as np
x=df.iloc[:,1:].values.flatten()
import scipy.stats as stats
from scipy.stats import normaltest
stats.normaltest(x,axis=None)
This gives me nicely a p-value and a statistic.
The only thing I want right now is to:
Add 2 columns in the file with this p value and statistic and if i have multiple rows, do it for all the rows (calculate p value & statistic for each row and add 2 columns with these values in it).
Can someone help?
python-3.x pandas statistics
If you want to add a column you may do this:df['name_of_new_colum'] = value_to_store
– jalazbe
Nov 25 '18 at 19:12
thanks, but how can I put the p value in one column and the statistic in the other. Seems I can't split them up...
– Steven Pauly
Nov 25 '18 at 19:17
add a comment |
I got the following simple code to calculate normality over an array:
import pandas as pd
df = pd.read_excel("directoryfile.xlsx")
import numpy as np
x=df.iloc[:,1:].values.flatten()
import scipy.stats as stats
from scipy.stats import normaltest
stats.normaltest(x,axis=None)
This gives me nicely a p-value and a statistic.
The only thing I want right now is to:
Add 2 columns in the file with this p value and statistic and if i have multiple rows, do it for all the rows (calculate p value & statistic for each row and add 2 columns with these values in it).
Can someone help?
python-3.x pandas statistics
I got the following simple code to calculate normality over an array:
import pandas as pd
df = pd.read_excel("directoryfile.xlsx")
import numpy as np
x=df.iloc[:,1:].values.flatten()
import scipy.stats as stats
from scipy.stats import normaltest
stats.normaltest(x,axis=None)
This gives me nicely a p-value and a statistic.
The only thing I want right now is to:
Add 2 columns in the file with this p value and statistic and if i have multiple rows, do it for all the rows (calculate p value & statistic for each row and add 2 columns with these values in it).
Can someone help?
python-3.x pandas statistics
python-3.x pandas statistics
edited Nov 25 '18 at 19:16
desertnaut
19.8k74178
19.8k74178
asked Nov 25 '18 at 18:56
Steven PaulySteven Pauly
528
528
If you want to add a column you may do this:df['name_of_new_colum'] = value_to_store
– jalazbe
Nov 25 '18 at 19:12
thanks, but how can I put the p value in one column and the statistic in the other. Seems I can't split them up...
– Steven Pauly
Nov 25 '18 at 19:17
add a comment |
If you want to add a column you may do this:df['name_of_new_colum'] = value_to_store
– jalazbe
Nov 25 '18 at 19:12
thanks, but how can I put the p value in one column and the statistic in the other. Seems I can't split them up...
– Steven Pauly
Nov 25 '18 at 19:17
If you want to add a column you may do this:
df['name_of_new_colum'] = value_to_store
– jalazbe
Nov 25 '18 at 19:12
If you want to add a column you may do this:
df['name_of_new_colum'] = value_to_store
– jalazbe
Nov 25 '18 at 19:12
thanks, but how can I put the p value in one column and the statistic in the other. Seems I can't split them up...
– Steven Pauly
Nov 25 '18 at 19:17
thanks, but how can I put the p value in one column and the statistic in the other. Seems I can't split them up...
– Steven Pauly
Nov 25 '18 at 19:17
add a comment |
1 Answer
1
active
oldest
votes
If you want to calculate row-wise normaltest
, you should not flatten
your data in x
and use axis=1
such as
df = pd.DataFrame(np.random.random(105).reshape(5,21)) # to generate data
# calculate normaltest row-wise without the first column like you
df['stat'] ,df['p'] = stats.normaltest(df.iloc[:,1:],axis=1)
Then df
contains two columns 'stat' and 'p' with the values your are looking for IIUC.
Note: to be able to perform normaltest
, you need at least 8 values (according to what I experienced) so you need at least 8 columns in df.iloc[:,1:]
otherwise it will raise an error. And even, it would be better to have more than 20 values in each row.
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%2f53470816%2fp-value-normal-test-for-multiple-rows%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
If you want to calculate row-wise normaltest
, you should not flatten
your data in x
and use axis=1
such as
df = pd.DataFrame(np.random.random(105).reshape(5,21)) # to generate data
# calculate normaltest row-wise without the first column like you
df['stat'] ,df['p'] = stats.normaltest(df.iloc[:,1:],axis=1)
Then df
contains two columns 'stat' and 'p' with the values your are looking for IIUC.
Note: to be able to perform normaltest
, you need at least 8 values (according to what I experienced) so you need at least 8 columns in df.iloc[:,1:]
otherwise it will raise an error. And even, it would be better to have more than 20 values in each row.
add a comment |
If you want to calculate row-wise normaltest
, you should not flatten
your data in x
and use axis=1
such as
df = pd.DataFrame(np.random.random(105).reshape(5,21)) # to generate data
# calculate normaltest row-wise without the first column like you
df['stat'] ,df['p'] = stats.normaltest(df.iloc[:,1:],axis=1)
Then df
contains two columns 'stat' and 'p' with the values your are looking for IIUC.
Note: to be able to perform normaltest
, you need at least 8 values (according to what I experienced) so you need at least 8 columns in df.iloc[:,1:]
otherwise it will raise an error. And even, it would be better to have more than 20 values in each row.
add a comment |
If you want to calculate row-wise normaltest
, you should not flatten
your data in x
and use axis=1
such as
df = pd.DataFrame(np.random.random(105).reshape(5,21)) # to generate data
# calculate normaltest row-wise without the first column like you
df['stat'] ,df['p'] = stats.normaltest(df.iloc[:,1:],axis=1)
Then df
contains two columns 'stat' and 'p' with the values your are looking for IIUC.
Note: to be able to perform normaltest
, you need at least 8 values (according to what I experienced) so you need at least 8 columns in df.iloc[:,1:]
otherwise it will raise an error. And even, it would be better to have more than 20 values in each row.
If you want to calculate row-wise normaltest
, you should not flatten
your data in x
and use axis=1
such as
df = pd.DataFrame(np.random.random(105).reshape(5,21)) # to generate data
# calculate normaltest row-wise without the first column like you
df['stat'] ,df['p'] = stats.normaltest(df.iloc[:,1:],axis=1)
Then df
contains two columns 'stat' and 'p' with the values your are looking for IIUC.
Note: to be able to perform normaltest
, you need at least 8 values (according to what I experienced) so you need at least 8 columns in df.iloc[:,1:]
otherwise it will raise an error. And even, it would be better to have more than 20 values in each row.
answered Nov 25 '18 at 20:15
Ben.TBen.T
6,5052928
6,5052928
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.
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%2f53470816%2fp-value-normal-test-for-multiple-rows%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
If you want to add a column you may do this:
df['name_of_new_colum'] = value_to_store
– jalazbe
Nov 25 '18 at 19:12
thanks, but how can I put the p value in one column and the statistic in the other. Seems I can't split them up...
– Steven Pauly
Nov 25 '18 at 19:17