Convert the continuous values of grades into classes





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have the following dataframe int_stdf (Fig. 1) and I need to do the following:



Consider the values in G1, G2 and G3 being >= 10 as pass(1) and < 10 as fail(0) and encode them into binary values. Print head of dataframe to check the values.



        G1  G2  G3
number
0 5 6 6
1 5 5 6
2 7 8 10
3 15 14 15
4 6 10 10
5 15 15 15


Fig. 1



        G1  G2  G3
number
0 0 0 0
1 0 0 0
2 0 0 1
3 1 1 1
4 0 1 1
5 1 1 1


Fig. 2



So I should get something like (Fig. 2):



Please advise how to achieve this.










share|improve this question




















  • 5





    df.ge(10).astype(int)

    – ALollz
    Jan 3 at 16:31






  • 3





    Sounds like a homework assignment of some sort. What have you done? Please post your code and explain why you are not happy with it.

    – DYZ
    Jan 3 at 16:31


















1















I have the following dataframe int_stdf (Fig. 1) and I need to do the following:



Consider the values in G1, G2 and G3 being >= 10 as pass(1) and < 10 as fail(0) and encode them into binary values. Print head of dataframe to check the values.



        G1  G2  G3
number
0 5 6 6
1 5 5 6
2 7 8 10
3 15 14 15
4 6 10 10
5 15 15 15


Fig. 1



        G1  G2  G3
number
0 0 0 0
1 0 0 0
2 0 0 1
3 1 1 1
4 0 1 1
5 1 1 1


Fig. 2



So I should get something like (Fig. 2):



Please advise how to achieve this.










share|improve this question




















  • 5





    df.ge(10).astype(int)

    – ALollz
    Jan 3 at 16:31






  • 3





    Sounds like a homework assignment of some sort. What have you done? Please post your code and explain why you are not happy with it.

    – DYZ
    Jan 3 at 16:31














1












1








1








I have the following dataframe int_stdf (Fig. 1) and I need to do the following:



Consider the values in G1, G2 and G3 being >= 10 as pass(1) and < 10 as fail(0) and encode them into binary values. Print head of dataframe to check the values.



        G1  G2  G3
number
0 5 6 6
1 5 5 6
2 7 8 10
3 15 14 15
4 6 10 10
5 15 15 15


Fig. 1



        G1  G2  G3
number
0 0 0 0
1 0 0 0
2 0 0 1
3 1 1 1
4 0 1 1
5 1 1 1


Fig. 2



So I should get something like (Fig. 2):



Please advise how to achieve this.










share|improve this question
















I have the following dataframe int_stdf (Fig. 1) and I need to do the following:



Consider the values in G1, G2 and G3 being >= 10 as pass(1) and < 10 as fail(0) and encode them into binary values. Print head of dataframe to check the values.



        G1  G2  G3
number
0 5 6 6
1 5 5 6
2 7 8 10
3 15 14 15
4 6 10 10
5 15 15 15


Fig. 1



        G1  G2  G3
number
0 0 0 0
1 0 0 0
2 0 0 1
3 1 1 1
4 0 1 1
5 1 1 1


Fig. 2



So I should get something like (Fig. 2):



Please advise how to achieve this.







python pandas






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 16:30









DYZ

28.4k62352




28.4k62352










asked Jan 3 at 16:29









Mohammad Amir AshraffMohammad Amir Ashraff

254




254








  • 5





    df.ge(10).astype(int)

    – ALollz
    Jan 3 at 16:31






  • 3





    Sounds like a homework assignment of some sort. What have you done? Please post your code and explain why you are not happy with it.

    – DYZ
    Jan 3 at 16:31














  • 5





    df.ge(10).astype(int)

    – ALollz
    Jan 3 at 16:31






  • 3





    Sounds like a homework assignment of some sort. What have you done? Please post your code and explain why you are not happy with it.

    – DYZ
    Jan 3 at 16:31








5




5





df.ge(10).astype(int)

– ALollz
Jan 3 at 16:31





df.ge(10).astype(int)

– ALollz
Jan 3 at 16:31




3




3





Sounds like a homework assignment of some sort. What have you done? Please post your code and explain why you are not happy with it.

– DYZ
Jan 3 at 16:31





Sounds like a homework assignment of some sort. What have you done? Please post your code and explain why you are not happy with it.

– DYZ
Jan 3 at 16:31












1 Answer
1






active

oldest

votes


















3














You could use np.where:



pd.DataFrame(np.where(df >= 10, 1, 0), columns=df.columns)

G1 G2 G3
0 0 0 0
1 0 0 0
2 0 0 1
3 1 1 1
4 0 1 1
5 1 1 1





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%2f54026223%2fconvert-the-continuous-values-of-grades-into-classes%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









    3














    You could use np.where:



    pd.DataFrame(np.where(df >= 10, 1, 0), columns=df.columns)

    G1 G2 G3
    0 0 0 0
    1 0 0 0
    2 0 0 1
    3 1 1 1
    4 0 1 1
    5 1 1 1





    share|improve this answer




























      3














      You could use np.where:



      pd.DataFrame(np.where(df >= 10, 1, 0), columns=df.columns)

      G1 G2 G3
      0 0 0 0
      1 0 0 0
      2 0 0 1
      3 1 1 1
      4 0 1 1
      5 1 1 1





      share|improve this answer


























        3












        3








        3







        You could use np.where:



        pd.DataFrame(np.where(df >= 10, 1, 0), columns=df.columns)

        G1 G2 G3
        0 0 0 0
        1 0 0 0
        2 0 0 1
        3 1 1 1
        4 0 1 1
        5 1 1 1





        share|improve this answer













        You could use np.where:



        pd.DataFrame(np.where(df >= 10, 1, 0), columns=df.columns)

        G1 G2 G3
        0 0 0 0
        1 0 0 0
        2 0 0 1
        3 1 1 1
        4 0 1 1
        5 1 1 1






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 16:31









        yatuyatu

        15.8k41642




        15.8k41642
































            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%2f54026223%2fconvert-the-continuous-values-of-grades-into-classes%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

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            How to fix TextFormField cause rebuild widget in Flutter