Find quick method for Filling Missing Categorical Values with Categories already in the Same Column using a Second Column as CorrespondencePandas fill missing values in dataframe from another dataframeFind maximum value of a column and return the corresponding row values using PandasImpute categorical missing values in scikit-learnReplace substring string in one table with string in another table for an entire columnFinding the corresponding value in pythonReplacing the missing categorical values in a categorical columnPandas - fill missing column values with corresponding id column valuesFilling out missing values in columns?How to fill missing category variable?Pandas Fill column value with next available value in the same columnFilling missing values in dataframe column Python

Unlock your Lock

about to retire but not retired yet, employed but not working any more

What are the occurences of total war in the Native Americans?

Discussing work with supervisor in an invited dinner with his family

Half filled water bottle

How much does Commander Data weigh?

How is linear momentum conserved in case of a freely falling body?

Why did my folder names end up like this, and how can I fix this using a script?

Why is "-ber" the suffix of the last four months of the year?

Is this password scheme legit?

How to say "I only speak one which is English." in French?

What stops you from using fixed income in developing countries?

Why error propagation in CBC mode encryption affect two blocks?

Can I get a PhD for developing an educational software?

Do clerics commit a sin if they do not recite the liturgy of the hours?

How to socialize at pubs/bars when you are alone?

Why is getting a PhD considered "financially irresponsible"?

"There were either twelve sexes or none."

What is the loud noise of a helicopter when the rotors are not yet moving?

What are these white rings in the Undead parish?

Why is strlen so complex in C?

Hangman game in Python - need feedback on the quality of code

Do you pay one or two mana to bounce a transformed Delver of Secrets with Repeal?

What is the meaning of “these lederhosen are riding up my Bundesliga”?



Find quick method for Filling Missing Categorical Values with Categories already in the Same Column using a Second Column as Correspondence


Pandas fill missing values in dataframe from another dataframeFind maximum value of a column and return the corresponding row values using PandasImpute categorical missing values in scikit-learnReplace substring string in one table with string in another table for an entire columnFinding the corresponding value in pythonReplacing the missing categorical values in a categorical columnPandas - fill missing column values with corresponding id column valuesFilling out missing values in columns?How to fill missing category variable?Pandas Fill column value with next available value in the same columnFilling missing values in dataframe column Python






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















As you can see in the screenshot, the values of the code column correspond with the values of the name column. That's because the code is for the project code and the name is for the project name.



How can I fill the missing values of the name column using the code column as a correspondence? Is there any method that can take care of that?



 code name countryshortname
212 1 Liberia
2 1 Economic management Tunisia
1211 1 Economic management Tonga
1045 1 Economic management Macedonia, former Yugoslav Republic of
363 1 Cote d'Ivoire
453 1 Economic management Lesotho
784 1 Economic management Tanzania
648 1 Economic management Lao People's Democratic Republic
647 1 Economic management Lao People's Democratic Republic
204 1 Economic management Kyrgyz Republic
205 1 Economic management Kyrgyz Republic
249 1 Economic management Armenia
1437 1 Guatemala
1212 1 Economic management Kenya
1114 1 Honduras

[ScreenShot of Actual Dataframe][1]


[1]: https://i.stack.imgur.com/eq6xt.png









share|improve this question


























  • Please provide samples of your dataframes in the question text, not as images. Additionally, what have you tried so far? Please provide a minimal reproducible example

    – G. Anderson
    Mar 27 at 20:14











  • i haven't tried anything yet, because the drop methods don't look like they would work. i was trying to write a for loop but i figured i should ask about already existing methods before writing a function. i don't know how to provide a sample without typing out a part of the dataframe.

    – Carlos Rivas
    Mar 27 at 20:25











  • It's hard to tell from your question, but this looks like it could be done with a merge or join maybe. As for providing the data, typing up or copy-pasting a sample is what you should do. df.head() or df.sample() are great for creating small dfs to paste in

    – G. Anderson
    Mar 27 at 20:30











  • i believe merge is for merging several dataframes on a column, that's not what i'm doing.

    – Carlos Rivas
    Mar 27 at 20:51











  • Sorry, I misunderstood the question, but here is a question with some answers you might find helpful

    – G. Anderson
    Mar 27 at 20:57


















0















As you can see in the screenshot, the values of the code column correspond with the values of the name column. That's because the code is for the project code and the name is for the project name.



How can I fill the missing values of the name column using the code column as a correspondence? Is there any method that can take care of that?



 code name countryshortname
212 1 Liberia
2 1 Economic management Tunisia
1211 1 Economic management Tonga
1045 1 Economic management Macedonia, former Yugoslav Republic of
363 1 Cote d'Ivoire
453 1 Economic management Lesotho
784 1 Economic management Tanzania
648 1 Economic management Lao People's Democratic Republic
647 1 Economic management Lao People's Democratic Republic
204 1 Economic management Kyrgyz Republic
205 1 Economic management Kyrgyz Republic
249 1 Economic management Armenia
1437 1 Guatemala
1212 1 Economic management Kenya
1114 1 Honduras

[ScreenShot of Actual Dataframe][1]


[1]: https://i.stack.imgur.com/eq6xt.png









share|improve this question


























  • Please provide samples of your dataframes in the question text, not as images. Additionally, what have you tried so far? Please provide a minimal reproducible example

    – G. Anderson
    Mar 27 at 20:14











  • i haven't tried anything yet, because the drop methods don't look like they would work. i was trying to write a for loop but i figured i should ask about already existing methods before writing a function. i don't know how to provide a sample without typing out a part of the dataframe.

    – Carlos Rivas
    Mar 27 at 20:25











  • It's hard to tell from your question, but this looks like it could be done with a merge or join maybe. As for providing the data, typing up or copy-pasting a sample is what you should do. df.head() or df.sample() are great for creating small dfs to paste in

    – G. Anderson
    Mar 27 at 20:30











  • i believe merge is for merging several dataframes on a column, that's not what i'm doing.

    – Carlos Rivas
    Mar 27 at 20:51











  • Sorry, I misunderstood the question, but here is a question with some answers you might find helpful

    – G. Anderson
    Mar 27 at 20:57














0












0








0








As you can see in the screenshot, the values of the code column correspond with the values of the name column. That's because the code is for the project code and the name is for the project name.



How can I fill the missing values of the name column using the code column as a correspondence? Is there any method that can take care of that?



 code name countryshortname
212 1 Liberia
2 1 Economic management Tunisia
1211 1 Economic management Tonga
1045 1 Economic management Macedonia, former Yugoslav Republic of
363 1 Cote d'Ivoire
453 1 Economic management Lesotho
784 1 Economic management Tanzania
648 1 Economic management Lao People's Democratic Republic
647 1 Economic management Lao People's Democratic Republic
204 1 Economic management Kyrgyz Republic
205 1 Economic management Kyrgyz Republic
249 1 Economic management Armenia
1437 1 Guatemala
1212 1 Economic management Kenya
1114 1 Honduras

[ScreenShot of Actual Dataframe][1]


[1]: https://i.stack.imgur.com/eq6xt.png









share|improve this question
















As you can see in the screenshot, the values of the code column correspond with the values of the name column. That's because the code is for the project code and the name is for the project name.



How can I fill the missing values of the name column using the code column as a correspondence? Is there any method that can take care of that?



 code name countryshortname
212 1 Liberia
2 1 Economic management Tunisia
1211 1 Economic management Tonga
1045 1 Economic management Macedonia, former Yugoslav Republic of
363 1 Cote d'Ivoire
453 1 Economic management Lesotho
784 1 Economic management Tanzania
648 1 Economic management Lao People's Democratic Republic
647 1 Economic management Lao People's Democratic Republic
204 1 Economic management Kyrgyz Republic
205 1 Economic management Kyrgyz Republic
249 1 Economic management Armenia
1437 1 Guatemala
1212 1 Economic management Kenya
1114 1 Honduras

[ScreenShot of Actual Dataframe][1]


[1]: https://i.stack.imgur.com/eq6xt.png






python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 20:37







Carlos Rivas

















asked Mar 27 at 19:59









Carlos RivasCarlos Rivas

14 bronze badges




14 bronze badges















  • Please provide samples of your dataframes in the question text, not as images. Additionally, what have you tried so far? Please provide a minimal reproducible example

    – G. Anderson
    Mar 27 at 20:14











  • i haven't tried anything yet, because the drop methods don't look like they would work. i was trying to write a for loop but i figured i should ask about already existing methods before writing a function. i don't know how to provide a sample without typing out a part of the dataframe.

    – Carlos Rivas
    Mar 27 at 20:25











  • It's hard to tell from your question, but this looks like it could be done with a merge or join maybe. As for providing the data, typing up or copy-pasting a sample is what you should do. df.head() or df.sample() are great for creating small dfs to paste in

    – G. Anderson
    Mar 27 at 20:30











  • i believe merge is for merging several dataframes on a column, that's not what i'm doing.

    – Carlos Rivas
    Mar 27 at 20:51











  • Sorry, I misunderstood the question, but here is a question with some answers you might find helpful

    – G. Anderson
    Mar 27 at 20:57


















  • Please provide samples of your dataframes in the question text, not as images. Additionally, what have you tried so far? Please provide a minimal reproducible example

    – G. Anderson
    Mar 27 at 20:14











  • i haven't tried anything yet, because the drop methods don't look like they would work. i was trying to write a for loop but i figured i should ask about already existing methods before writing a function. i don't know how to provide a sample without typing out a part of the dataframe.

    – Carlos Rivas
    Mar 27 at 20:25











  • It's hard to tell from your question, but this looks like it could be done with a merge or join maybe. As for providing the data, typing up or copy-pasting a sample is what you should do. df.head() or df.sample() are great for creating small dfs to paste in

    – G. Anderson
    Mar 27 at 20:30











  • i believe merge is for merging several dataframes on a column, that's not what i'm doing.

    – Carlos Rivas
    Mar 27 at 20:51











  • Sorry, I misunderstood the question, but here is a question with some answers you might find helpful

    – G. Anderson
    Mar 27 at 20:57

















Please provide samples of your dataframes in the question text, not as images. Additionally, what have you tried so far? Please provide a minimal reproducible example

– G. Anderson
Mar 27 at 20:14





Please provide samples of your dataframes in the question text, not as images. Additionally, what have you tried so far? Please provide a minimal reproducible example

– G. Anderson
Mar 27 at 20:14













i haven't tried anything yet, because the drop methods don't look like they would work. i was trying to write a for loop but i figured i should ask about already existing methods before writing a function. i don't know how to provide a sample without typing out a part of the dataframe.

– Carlos Rivas
Mar 27 at 20:25





i haven't tried anything yet, because the drop methods don't look like they would work. i was trying to write a for loop but i figured i should ask about already existing methods before writing a function. i don't know how to provide a sample without typing out a part of the dataframe.

– Carlos Rivas
Mar 27 at 20:25













It's hard to tell from your question, but this looks like it could be done with a merge or join maybe. As for providing the data, typing up or copy-pasting a sample is what you should do. df.head() or df.sample() are great for creating small dfs to paste in

– G. Anderson
Mar 27 at 20:30





It's hard to tell from your question, but this looks like it could be done with a merge or join maybe. As for providing the data, typing up or copy-pasting a sample is what you should do. df.head() or df.sample() are great for creating small dfs to paste in

– G. Anderson
Mar 27 at 20:30













i believe merge is for merging several dataframes on a column, that's not what i'm doing.

– Carlos Rivas
Mar 27 at 20:51





i believe merge is for merging several dataframes on a column, that's not what i'm doing.

– Carlos Rivas
Mar 27 at 20:51













Sorry, I misunderstood the question, but here is a question with some answers you might find helpful

– G. Anderson
Mar 27 at 20:57






Sorry, I misunderstood the question, but here is a question with some answers you might find helpful

– G. Anderson
Mar 27 at 20:57













1 Answer
1






active

oldest

votes


















0















Because there is only one code/name combo in your question, I couldn;t test this more fully. But if you sort by code then name, you should be able to just forward fill the NaN values



df['name']=df.sort_values(['code','name'])['name'].fillna(method='ffill')

code name countryshortname
212 1 Economic Liberia
2 1 Economic Tunisia
1211 1 Economic Tonga
1045 1 Economic Macedonia
363 1 Economic Cote
453 1 Economic Lesotho
784 1 Economic Tanzania
648 1 Economic Lao
647 1 Economic Lao
204 1 Economic Kyrgyz
205 1 Economic Kyrgyz
249 1 Economic Armenia
1437 1 Economic Guatemala
1212 1 Economic Kenya
1114 1 Economic Honduras





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%2f55385532%2ffind-quick-method-for-filling-missing-categorical-values-with-categories-already%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









    0















    Because there is only one code/name combo in your question, I couldn;t test this more fully. But if you sort by code then name, you should be able to just forward fill the NaN values



    df['name']=df.sort_values(['code','name'])['name'].fillna(method='ffill')

    code name countryshortname
    212 1 Economic Liberia
    2 1 Economic Tunisia
    1211 1 Economic Tonga
    1045 1 Economic Macedonia
    363 1 Economic Cote
    453 1 Economic Lesotho
    784 1 Economic Tanzania
    648 1 Economic Lao
    647 1 Economic Lao
    204 1 Economic Kyrgyz
    205 1 Economic Kyrgyz
    249 1 Economic Armenia
    1437 1 Economic Guatemala
    1212 1 Economic Kenya
    1114 1 Economic Honduras





    share|improve this answer





























      0















      Because there is only one code/name combo in your question, I couldn;t test this more fully. But if you sort by code then name, you should be able to just forward fill the NaN values



      df['name']=df.sort_values(['code','name'])['name'].fillna(method='ffill')

      code name countryshortname
      212 1 Economic Liberia
      2 1 Economic Tunisia
      1211 1 Economic Tonga
      1045 1 Economic Macedonia
      363 1 Economic Cote
      453 1 Economic Lesotho
      784 1 Economic Tanzania
      648 1 Economic Lao
      647 1 Economic Lao
      204 1 Economic Kyrgyz
      205 1 Economic Kyrgyz
      249 1 Economic Armenia
      1437 1 Economic Guatemala
      1212 1 Economic Kenya
      1114 1 Economic Honduras





      share|improve this answer



























        0














        0










        0









        Because there is only one code/name combo in your question, I couldn;t test this more fully. But if you sort by code then name, you should be able to just forward fill the NaN values



        df['name']=df.sort_values(['code','name'])['name'].fillna(method='ffill')

        code name countryshortname
        212 1 Economic Liberia
        2 1 Economic Tunisia
        1211 1 Economic Tonga
        1045 1 Economic Macedonia
        363 1 Economic Cote
        453 1 Economic Lesotho
        784 1 Economic Tanzania
        648 1 Economic Lao
        647 1 Economic Lao
        204 1 Economic Kyrgyz
        205 1 Economic Kyrgyz
        249 1 Economic Armenia
        1437 1 Economic Guatemala
        1212 1 Economic Kenya
        1114 1 Economic Honduras





        share|improve this answer













        Because there is only one code/name combo in your question, I couldn;t test this more fully. But if you sort by code then name, you should be able to just forward fill the NaN values



        df['name']=df.sort_values(['code','name'])['name'].fillna(method='ffill')

        code name countryshortname
        212 1 Economic Liberia
        2 1 Economic Tunisia
        1211 1 Economic Tonga
        1045 1 Economic Macedonia
        363 1 Economic Cote
        453 1 Economic Lesotho
        784 1 Economic Tanzania
        648 1 Economic Lao
        647 1 Economic Lao
        204 1 Economic Kyrgyz
        205 1 Economic Kyrgyz
        249 1 Economic Armenia
        1437 1 Economic Guatemala
        1212 1 Economic Kenya
        1114 1 Economic Honduras






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 15:45









        G. AndersonG. Anderson

        2,8411 gold badge6 silver badges13 bronze badges




        2,8411 gold badge6 silver badges13 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            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%2f55385532%2ffind-quick-method-for-filling-missing-categorical-values-with-categories-already%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현