How can I check whether a column contains strings in pandas Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!pandas invalid literal for long() with base 10 errorHow 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 in Python?How do I check if a string is a number (float)?How can I make a time delay in Python?Does Python have a string 'contains' substring method?Renaming columns in pandasDelete column from pandas DataFrame by column nameHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandas

Unix AIX passing variable and arguments to expect and spawn

Who's this lady in the war room?

Can this water damage be explained by lack of gutters and grading issues?

Is my guitar’s action too high?

Does the Pact of the Blade warlock feature allow me to customize the properties of the pact weapon I create?

What could prevent concentrated local exploration?

Knights and Knaves question

Married in secret, can marital status in passport be changed at a later date?

Is it OK if I do not take the receipt in Germany?

Coin Game with infinite paradox

Can a Knight grant Knighthood to another?

How to make an animal which can only breed for a certain number of generations?

Etymology of 見舞い

Can I ask an author to send me his ebook?

What helicopter has the most rotor blades?

Normal Operator || T^2|| = ||T||^2

Lights are flickering on and off after accidentally bumping into light switch

Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?

Marquee sign letters

tabularx column has extra padding at right?

What is the definining line between a helicopter and a drone a person can ride in?

Is Vivien of the Wilds + Wilderness Reclamation a competitive combo?

Im stuck and having trouble with ¬P ∨ Q Prove: P → Q

Providing direct feedback to a product salesperson



How can I check whether a column contains strings in pandas



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!pandas invalid literal for long() with base 10 errorHow 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 in Python?How do I check if a string is a number (float)?How can I make a time delay in Python?Does Python have a string 'contains' substring method?Renaming columns in pandasDelete column from pandas DataFrame by column nameHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandas



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








2















The codes are below. I want to create a new column "value_c" based on simple operation on column "value".



frame['value_c'] = frame['value'].apply(lambda x: (x-32) / (5/9))


However, I got an error message like below.



TypeError: unsupported operand type(s) for -: 'str' and 'int'


How can I check whether the column has strings and how can I delete them?



Thank you!!!










share|improve this question






























    2















    The codes are below. I want to create a new column "value_c" based on simple operation on column "value".



    frame['value_c'] = frame['value'].apply(lambda x: (x-32) / (5/9))


    However, I got an error message like below.



    TypeError: unsupported operand type(s) for -: 'str' and 'int'


    How can I check whether the column has strings and how can I delete them?



    Thank you!!!










    share|improve this question


























      2












      2








      2








      The codes are below. I want to create a new column "value_c" based on simple operation on column "value".



      frame['value_c'] = frame['value'].apply(lambda x: (x-32) / (5/9))


      However, I got an error message like below.



      TypeError: unsupported operand type(s) for -: 'str' and 'int'


      How can I check whether the column has strings and how can I delete them?



      Thank you!!!










      share|improve this question
















      The codes are below. I want to create a new column "value_c" based on simple operation on column "value".



      frame['value_c'] = frame['value'].apply(lambda x: (x-32) / (5/9))


      However, I got an error message like below.



      TypeError: unsupported operand type(s) for -: 'str' and 'int'


      How can I check whether the column has strings and how can I delete them?



      Thank you!!!







      python pandas






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 9 at 3:02









      U9-Forward

      18.6k51744




      18.6k51744










      asked Mar 9 at 2:49









      Yabin DaYabin Da

      133




      133






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Use pd.to_numeric then dropna:



          frame['value_c'] = pd.to_numeric(frame['value'],errors='coerce').dropna().apply(lambda x: (x-32) / (5/9))


          Then it will work as expected.






          share|improve this answer























          • or we can use .astype(int) to convert then dropna() and apply..

            – hacker315
            Mar 9 at 4:30






          • 2





            @hacker315 there are few cases where you cannot .astype(int) check this: stackoverflow.com/questions/38918653/…

            – anky_91
            Mar 9 at 4:44











          • @hacker315 Yeah, anky_91 is correct, you only can do astype(int) to string integers

            – U9-Forward
            Mar 9 at 5:38






          • 1





            Yeap. This code works for me.

            – Yabin Da
            Mar 9 at 15:07











          • @YabinDa Happy to help :-)

            – U9-Forward
            Mar 10 at 1:31











          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%2f55073538%2fhow-can-i-check-whether-a-column-contains-strings-in-pandas%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









          1














          Use pd.to_numeric then dropna:



          frame['value_c'] = pd.to_numeric(frame['value'],errors='coerce').dropna().apply(lambda x: (x-32) / (5/9))


          Then it will work as expected.






          share|improve this answer























          • or we can use .astype(int) to convert then dropna() and apply..

            – hacker315
            Mar 9 at 4:30






          • 2





            @hacker315 there are few cases where you cannot .astype(int) check this: stackoverflow.com/questions/38918653/…

            – anky_91
            Mar 9 at 4:44











          • @hacker315 Yeah, anky_91 is correct, you only can do astype(int) to string integers

            – U9-Forward
            Mar 9 at 5:38






          • 1





            Yeap. This code works for me.

            – Yabin Da
            Mar 9 at 15:07











          • @YabinDa Happy to help :-)

            – U9-Forward
            Mar 10 at 1:31















          1














          Use pd.to_numeric then dropna:



          frame['value_c'] = pd.to_numeric(frame['value'],errors='coerce').dropna().apply(lambda x: (x-32) / (5/9))


          Then it will work as expected.






          share|improve this answer























          • or we can use .astype(int) to convert then dropna() and apply..

            – hacker315
            Mar 9 at 4:30






          • 2





            @hacker315 there are few cases where you cannot .astype(int) check this: stackoverflow.com/questions/38918653/…

            – anky_91
            Mar 9 at 4:44











          • @hacker315 Yeah, anky_91 is correct, you only can do astype(int) to string integers

            – U9-Forward
            Mar 9 at 5:38






          • 1





            Yeap. This code works for me.

            – Yabin Da
            Mar 9 at 15:07











          • @YabinDa Happy to help :-)

            – U9-Forward
            Mar 10 at 1:31













          1












          1








          1







          Use pd.to_numeric then dropna:



          frame['value_c'] = pd.to_numeric(frame['value'],errors='coerce').dropna().apply(lambda x: (x-32) / (5/9))


          Then it will work as expected.






          share|improve this answer













          Use pd.to_numeric then dropna:



          frame['value_c'] = pd.to_numeric(frame['value'],errors='coerce').dropna().apply(lambda x: (x-32) / (5/9))


          Then it will work as expected.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 9 at 2:55









          U9-ForwardU9-Forward

          18.6k51744




          18.6k51744












          • or we can use .astype(int) to convert then dropna() and apply..

            – hacker315
            Mar 9 at 4:30






          • 2





            @hacker315 there are few cases where you cannot .astype(int) check this: stackoverflow.com/questions/38918653/…

            – anky_91
            Mar 9 at 4:44











          • @hacker315 Yeah, anky_91 is correct, you only can do astype(int) to string integers

            – U9-Forward
            Mar 9 at 5:38






          • 1





            Yeap. This code works for me.

            – Yabin Da
            Mar 9 at 15:07











          • @YabinDa Happy to help :-)

            – U9-Forward
            Mar 10 at 1:31

















          • or we can use .astype(int) to convert then dropna() and apply..

            – hacker315
            Mar 9 at 4:30






          • 2





            @hacker315 there are few cases where you cannot .astype(int) check this: stackoverflow.com/questions/38918653/…

            – anky_91
            Mar 9 at 4:44











          • @hacker315 Yeah, anky_91 is correct, you only can do astype(int) to string integers

            – U9-Forward
            Mar 9 at 5:38






          • 1





            Yeap. This code works for me.

            – Yabin Da
            Mar 9 at 15:07











          • @YabinDa Happy to help :-)

            – U9-Forward
            Mar 10 at 1:31
















          or we can use .astype(int) to convert then dropna() and apply..

          – hacker315
          Mar 9 at 4:30





          or we can use .astype(int) to convert then dropna() and apply..

          – hacker315
          Mar 9 at 4:30




          2




          2





          @hacker315 there are few cases where you cannot .astype(int) check this: stackoverflow.com/questions/38918653/…

          – anky_91
          Mar 9 at 4:44





          @hacker315 there are few cases where you cannot .astype(int) check this: stackoverflow.com/questions/38918653/…

          – anky_91
          Mar 9 at 4:44













          @hacker315 Yeah, anky_91 is correct, you only can do astype(int) to string integers

          – U9-Forward
          Mar 9 at 5:38





          @hacker315 Yeah, anky_91 is correct, you only can do astype(int) to string integers

          – U9-Forward
          Mar 9 at 5:38




          1




          1





          Yeap. This code works for me.

          – Yabin Da
          Mar 9 at 15:07





          Yeap. This code works for me.

          – Yabin Da
          Mar 9 at 15:07













          @YabinDa Happy to help :-)

          – U9-Forward
          Mar 10 at 1:31





          @YabinDa Happy to help :-)

          – U9-Forward
          Mar 10 at 1:31



















          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%2f55073538%2fhow-can-i-check-whether-a-column-contains-strings-in-pandas%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

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко