Empty Na in dataFrame columns











up vote
0
down vote

favorite












df



  Letter    city    state
0 A NYC NY
1 B Na CT
2 C LA Na
3 D Tampa FL
4 E Na Na
5 F Dallas TX
6 G Denver CL

df['city']=df['city'].str.replace("Na"," ")
df['state']=df['state'].str.replace("Na"," ")


df



    Letter  city    state
0 A NYC NY
1 B CT
2 C LA
3 D Tampa FL
4 E
5 F Dallas TX
6 G Denver CL

df.isnull().any()
Letter False
city False
state False
dtype: bool


How to empty Na to become:



Letter  False
city True
state True









share|improve this question




















  • 1




    Could you format your question and add the data in a way it can be copied and pasted directly into the editor.
    – Daniel Mesejo
    Nov 18 at 2:03















up vote
0
down vote

favorite












df



  Letter    city    state
0 A NYC NY
1 B Na CT
2 C LA Na
3 D Tampa FL
4 E Na Na
5 F Dallas TX
6 G Denver CL

df['city']=df['city'].str.replace("Na"," ")
df['state']=df['state'].str.replace("Na"," ")


df



    Letter  city    state
0 A NYC NY
1 B CT
2 C LA
3 D Tampa FL
4 E
5 F Dallas TX
6 G Denver CL

df.isnull().any()
Letter False
city False
state False
dtype: bool


How to empty Na to become:



Letter  False
city True
state True









share|improve this question




















  • 1




    Could you format your question and add the data in a way it can be copied and pasted directly into the editor.
    – Daniel Mesejo
    Nov 18 at 2:03













up vote
0
down vote

favorite









up vote
0
down vote

favorite











df



  Letter    city    state
0 A NYC NY
1 B Na CT
2 C LA Na
3 D Tampa FL
4 E Na Na
5 F Dallas TX
6 G Denver CL

df['city']=df['city'].str.replace("Na"," ")
df['state']=df['state'].str.replace("Na"," ")


df



    Letter  city    state
0 A NYC NY
1 B CT
2 C LA
3 D Tampa FL
4 E
5 F Dallas TX
6 G Denver CL

df.isnull().any()
Letter False
city False
state False
dtype: bool


How to empty Na to become:



Letter  False
city True
state True









share|improve this question















df



  Letter    city    state
0 A NYC NY
1 B Na CT
2 C LA Na
3 D Tampa FL
4 E Na Na
5 F Dallas TX
6 G Denver CL

df['city']=df['city'].str.replace("Na"," ")
df['state']=df['state'].str.replace("Na"," ")


df



    Letter  city    state
0 A NYC NY
1 B CT
2 C LA
3 D Tampa FL
4 E
5 F Dallas TX
6 G Denver CL

df.isnull().any()
Letter False
city False
state False
dtype: bool


How to empty Na to become:



Letter  False
city True
state True






python dataframe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 at 2:37









d_kennetz

1,317515




1,317515










asked Nov 18 at 1:57









Ray

162




162








  • 1




    Could you format your question and add the data in a way it can be copied and pasted directly into the editor.
    – Daniel Mesejo
    Nov 18 at 2:03














  • 1




    Could you format your question and add the data in a way it can be copied and pasted directly into the editor.
    – Daniel Mesejo
    Nov 18 at 2:03








1




1




Could you format your question and add the data in a way it can be copied and pasted directly into the editor.
– Daniel Mesejo
Nov 18 at 2:03




Could you format your question and add the data in a way it can be copied and pasted directly into the editor.
– Daniel Mesejo
Nov 18 at 2:03












1 Answer
1






active

oldest

votes

















up vote
2
down vote













Starting with your original df, you can just do:



df.eq("Na").any()


Alternately, starting from the second df, after you replace Na with empty string, replace the empty strings with NaN:



import numpy as np

df.replace('', np.nan).isnull().any()


Both produce:



Letter    False
city True
state True
dtype: bool





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',
    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%2f53357240%2fempty-na-in-dataframe-columns%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








    up vote
    2
    down vote













    Starting with your original df, you can just do:



    df.eq("Na").any()


    Alternately, starting from the second df, after you replace Na with empty string, replace the empty strings with NaN:



    import numpy as np

    df.replace('', np.nan).isnull().any()


    Both produce:



    Letter    False
    city True
    state True
    dtype: bool





    share|improve this answer



























      up vote
      2
      down vote













      Starting with your original df, you can just do:



      df.eq("Na").any()


      Alternately, starting from the second df, after you replace Na with empty string, replace the empty strings with NaN:



      import numpy as np

      df.replace('', np.nan).isnull().any()


      Both produce:



      Letter    False
      city True
      state True
      dtype: bool





      share|improve this answer

























        up vote
        2
        down vote










        up vote
        2
        down vote









        Starting with your original df, you can just do:



        df.eq("Na").any()


        Alternately, starting from the second df, after you replace Na with empty string, replace the empty strings with NaN:



        import numpy as np

        df.replace('', np.nan).isnull().any()


        Both produce:



        Letter    False
        city True
        state True
        dtype: bool





        share|improve this answer














        Starting with your original df, you can just do:



        df.eq("Na").any()


        Alternately, starting from the second df, after you replace Na with empty string, replace the empty strings with NaN:



        import numpy as np

        df.replace('', np.nan).isnull().any()


        Both produce:



        Letter    False
        city True
        state True
        dtype: bool






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 18 at 4:46

























        answered Nov 18 at 2:42









        andrew_reece

        10.2k1927




        10.2k1927






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357240%2fempty-na-in-dataframe-columns%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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy