Skip to content
Advertisement

Remove rows in which string contains other letters than A,C,T,G,N

I’m fairly new to numpy and pandas, let’s say that I have a 2D numpy array and I need to delete all rows in which the second value contain only the letters 'A', 'C', 'T', 'G' and 'N'

JavaScript

so after filtering I can get this

JavaScript

I wanted to do 3 for loops that are checking each char one by one but this is sooo slow when I have 500 rows

Advertisement

Answer

Use Series.str.contains with values and ^ for start and $ for end of string:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement