I\'m trying to remove a group of columns from a dataset. All of the variables to remove end with the text \"prefix\".
I did manage to \"collect\' them into a group
for the sake of completeness:
In [306]: df
Out[306]:
prefixcol1 col2prefix col3prefix colN
0 1 1 1 1
1 2 2 2 2
2 3 3 3 3
In [307]: df.loc[:, ~df.columns.str.contains('prefix$')]
Out[307]:
prefixcol1 colN
0 1 1
1 2 2
2 3 3
or another variant:
In [388]: df.select(lambda x: re.search(r'prefix$', str(x)) is None, axis=1)
Out[388]:
prefixcol1 colN
0 1 1
1 2 2
2 3 3