Skip to content
Advertisement

Find columns where at least one row contains an alphabetical letter

Let’s say I have the following data set:

JavaScript

I would like to find out – without any cumbersome for loop – which columns contain at least one case with an alphabetical letter (here: B and C). I guess the result should either be a list of booleans or indices.

Thank you for your help!

Advertisement

Answer

As a quick and simple solution, you can use replace and filter:

JavaScript

Another option is applying str.contains column-wise:

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