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

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript