How to convert value's in DF by loop?How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory?Converting string into datetimeAccessing the index in 'for' loops?Convert bytes to a string?How do I sort a dictionary by value?How do I list all files of a directory?Iterating over dictionaries using 'for' loops

Could a 19.25mm revolver actually exist?

First Match - awk

A steel cutting sword?

Convert Byte array into collection of items of different types

Compaq Portable vs IBM 5155 Portable PC

Need to read my home electrical meter

Does COBRA make sense anymore with the ACA?

Why most published works in medical imaging try reducing false positives?

Is it possible to remotely hack the GPS system and disable GPS service worldwide?

Python program to take in two strings and print the larger string

Dad jokes are fun

How to respond to upset student?

Where's this lookout in Nova Scotia?

Why were helmets and other body armour not commonplace in the 1800s?

Apt - strange requests to d16r8ew072anqo.cloudfront.net:80

How should I introduce map drawing to my players?

Should one buy new hardware after a system compromise?

Count Even Digits In Number

Did 20% of US soldiers in Vietnam use heroin, 95% of whom quit afterwards?

Question in discrete mathematics about group permutations

Find the three digit Prime number P from the given unusual relationships

Is it rude to call a professor by their last name with no prefix in a non-academic setting?

Is the field of q-series 'dead'?

I know that there is a preselected candidate for a position to be filled at my department. What should I do?



How to convert value's in DF by loop?


How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory?Converting string into datetimeAccessing the index in 'for' loops?Convert bytes to a string?How do I sort a dictionary by value?How do I list all files of a directory?Iterating over dictionaries using 'for' loops






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








0















I have data set with string column and I had to convert them into int value the problem is some columns have 90+ different value and to convert them
manually and take time, there is a function to solve it automatically?



I did it, but manually:



price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all

app[`Price`] = app[`Price`].apply(lambda a: price_dict[a]) # 0 = free, 1 = not free

app[`Price`].value_counts() # To check.


I have tried :



 for x in app[`Price`]:

if x == 1:
price_dict = 91:0
else:
price_dict = x:1

app[`Price`] = app[`Price`].apply(lambda a: price_dict[a])# 0 = free, 1 = not free

app[`Price`].value_counts()









share|improve this question






























    0















    I have data set with string column and I had to convert them into int value the problem is some columns have 90+ different value and to convert them
    manually and take time, there is a function to solve it automatically?



    I did it, but manually:



    price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all

    app[`Price`] = app[`Price`].apply(lambda a: price_dict[a]) # 0 = free, 1 = not free

    app[`Price`].value_counts() # To check.


    I have tried :



     for x in app[`Price`]:

    if x == 1:
    price_dict = 91:0
    else:
    price_dict = x:1

    app[`Price`] = app[`Price`].apply(lambda a: price_dict[a])# 0 = free, 1 = not free

    app[`Price`].value_counts()









    share|improve this question


























      0












      0








      0


      1






      I have data set with string column and I had to convert them into int value the problem is some columns have 90+ different value and to convert them
      manually and take time, there is a function to solve it automatically?



      I did it, but manually:



      price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all

      app[`Price`] = app[`Price`].apply(lambda a: price_dict[a]) # 0 = free, 1 = not free

      app[`Price`].value_counts() # To check.


      I have tried :



       for x in app[`Price`]:

      if x == 1:
      price_dict = 91:0
      else:
      price_dict = x:1

      app[`Price`] = app[`Price`].apply(lambda a: price_dict[a])# 0 = free, 1 = not free

      app[`Price`].value_counts()









      share|improve this question
















      I have data set with string column and I had to convert them into int value the problem is some columns have 90+ different value and to convert them
      manually and take time, there is a function to solve it automatically?



      I did it, but manually:



      price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all

      app[`Price`] = app[`Price`].apply(lambda a: price_dict[a]) # 0 = free, 1 = not free

      app[`Price`].value_counts() # To check.


      I have tried :



       for x in app[`Price`]:

      if x == 1:
      price_dict = 91:0
      else:
      price_dict = x:1

      app[`Price`] = app[`Price`].apply(lambda a: price_dict[a])# 0 = free, 1 = not free

      app[`Price`].value_counts()






      python






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 5:11









      Miroslav Glamuzina

      2,85721223




      2,85721223










      asked Mar 24 at 2:31









      mim alamlkimim alamlki

      31




      31






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You can use map to transform a column using a dictionary to define the transformation:



          price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all

          app['Price'] = app['Price'].map(price_dict)

          app['Price'].value_counts()


          You can also replace values in columns like this:



          app['Price_new'] = 1

          app.loc[app.Price == 91, 'Price_new'] = 0





          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%2f55320244%2fhow-to-convert-values-in-df-by-loop%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














            You can use map to transform a column using a dictionary to define the transformation:



            price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all

            app['Price'] = app['Price'].map(price_dict)

            app['Price'].value_counts()


            You can also replace values in columns like this:



            app['Price_new'] = 1

            app.loc[app.Price == 91, 'Price_new'] = 0





            share|improve this answer





























              0














              You can use map to transform a column using a dictionary to define the transformation:



              price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all

              app['Price'] = app['Price'].map(price_dict)

              app['Price'].value_counts()


              You can also replace values in columns like this:



              app['Price_new'] = 1

              app.loc[app.Price == 91, 'Price_new'] = 0





              share|improve this answer



























                0












                0








                0







                You can use map to transform a column using a dictionary to define the transformation:



                price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all

                app['Price'] = app['Price'].map(price_dict)

                app['Price'].value_counts()


                You can also replace values in columns like this:



                app['Price_new'] = 1

                app.loc[app.Price == 91, 'Price_new'] = 0





                share|improve this answer















                You can use map to transform a column using a dictionary to define the transformation:



                price_dict = 91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1 # not all

                app['Price'] = app['Price'].map(price_dict)

                app['Price'].value_counts()


                You can also replace values in columns like this:



                app['Price_new'] = 1

                app.loc[app.Price == 91, 'Price_new'] = 0






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 24 at 2:41

























                answered Mar 24 at 2:35









                NathanielNathaniel

                2,225314




                2,225314





























                    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%2f55320244%2fhow-to-convert-values-in-df-by-loop%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권, 지리지 충청도 공주목 은진현