try this,
filtered_column=df.filter(regex=r'^p',axis=1).columns.values
df=df.drop(filtered_column, axis=1)
As you didn’t provide a sample data I created this my self.
Input:
p101 p102 p103 q21 qw32 kwp
0 68 17 54 67 93 36
1 32 22 56 69 38 6
2 58 48 89 68 60 79
3 64 14 63 53 7 86
4 67 94 47 94 73 53
5 96 34 87 83 12 18
6 15 62 47 4 22 53
7 3 63 12 24 68 14
8 22 32 17 45 96 44
9 19 48 37 75 53 22
Output:
q21 qw32 kwp
0 67 93 36
1 69 38 6
2 68 60 79
3 53 7 86
4 94 73 53
5 83 12 18
6 4 22 53
7 24 68 14
8 45 96 44
9 75 53 22
2
solved I’m trying to remove a group of columns from a dataset using python [closed]