if a specific column name is present drop tyhe column 1

if a specific column name is present drop tyhe column

df.columns.str.startswith('Test')
# array([ True, False, False, False])

df.loc[:,~df.columns.str.startswith('Test')]

  toto test2 riri
0    x     x    x
1    x     x    x

Here is what the above code is Doing:
1. df.columns.str.startswith(‘Test’) returns a boolean array of the same length as the number of columns in the dataframe.
2. ~df.columns.str.startswith(‘Test’) returns the negation of the boolean array.
3. df.loc[:,~df.columns.str.startswith(‘Test’)] returns the dataframe with only the columns whose names do not start with ‘Test’.

Similar Posts