P-value normal test for multiple rows












1















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?










share|improve this question

























  • 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
















1















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?










share|improve this question

























  • 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














1












1








1








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












1 Answer
1






active

oldest

votes


















1














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.






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%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









    1














    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.






    share|improve this answer




























      1














      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.






      share|improve this answer


























        1












        1








        1







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 20:15









        Ben.TBen.T

        6,5052928




        6,5052928
































            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%2f53470816%2fp-value-normal-test-for-multiple-rows%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

            Wiesbaden

            Marschland

            Dieringhausen