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 in df that do not startswith pattern

I have a dataframe in python, and I want to remove the rows that begins with "V10280", "V10281" or "V10282" in col "Variable".

variable
Capital
RM_RIDE
V1028196
V1028197
V1028198
V1028199
V1028200

I was thinking of something like this

a = a.loc[a['variable'].str.startswith(("V10280", "V10281", "V10282"))]

but with "not" or "!", such as

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

a = a.loc[a['variable'].str.startswith(!("V10280", "V10281", "V10282"))]

but this doesn’t work.

Thanks!!

>Solution :

try:

a = a.loc[~a['variable'].str.startswith(("V10280", "V10281", "V10282"))]
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