remove columns that contain string pandas

Solutions on MaxInterview for remove columns that contain string pandas by the best coders in the world

showing results for - "remove columns that contain string pandas"
Mía
16 Nov 2019
1df = df[df.columns.drop(list(df.filter(regex='Test')))]
2
Kedrick
29 Sep 2016
1import pandas as pd
2
3import numpy as np
4
5array=np.random.random((2,4))
6
7df=pd.DataFrame(array, columns=('Test1', 'toto', 'test2', 'riri'))
8
9print df
10
11      Test1      toto     test2      riri
120  0.923249  0.572528  0.845464  0.144891
131  0.020438  0.332540  0.144455  0.741412
14
15cols = [c for c in df.columns if c.lower()[:4] != 'test']
16
17df=df[cols]
18
19print df
20       toto      riri
210  0.572528  0.144891
221  0.332540  0.741412
23