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

How to filter pandas dataframe by a feature value ending with Case sensitive letter

I have a data frame like this:
df:

C1    C2
Ford  11
ram   13
SUV   19
SEDAN 14

I want to filter the data frame column C1 where the C1 values end with a upper case character. So the expected output looks like this:

C1    C2
SUV   19
SEDAN 14

I tried different regex approaches but nothing worked out for me.

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

Can anyone help me with this?

>Solution :

str.endswith doesn’t accept regexes, use str.contains:

df[df['C1'].str.contains('[A-Z]$')]

Output:

      C1  C2
2    SUV  19
3  SEDAN  14
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