Skip to content
Advertisement

How to find all columns contains string and put in a new columns?

I was wondering how could I find all values that start with ‘orange’ from all the columns and parse it into new columns.

JavaScript

expected output :

JavaScript

Advertisement

Answer

Let’s try stack then filter by str.contains:

JavaScript

df1:

JavaScript

Or melt for same order as OP:

JavaScript

df1:

JavaScript

regex ^orange:

  1. ^ asserts position at start of a line
  2. orange matches the characters orange literally (case sensitive)
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement