Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

filter rows from data where column salary has string datatype

idk how to ask Question maybe wrong way!

    id  name    salary
0   1   shyam   10000
1   2   ram     20000
2   3   ravi    abc
3   4   abhay   30000
4   5   karan   fgh

*** expected ***

       id   name    salary
  2    3    ravi    abc
  4    5    karan   fgh

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

We can use str.contains as follows:

df_out = df[(df["name"].str.contains(r'^[A-Za-z]+$', regex=True)) &
            (df["salary"].str.contains(r'^[A-Za-z]+$', regex=True))]

The above logic will only match rows for which both the name and salary columns contain only alpha characters.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading