Answers for "remove columns that contain string pandas"

0

remove columns that contain string pandas

df = df[df.columns.drop(list(df.filter(regex='Test')))]
Posted by: Guest on August-12-2021
0

remove columns that contain string pandas

import pandas as pd

import numpy as np

array=np.random.random((2,4))

df=pd.DataFrame(array, columns=('Test1', 'toto', 'test2', 'riri'))

print df

      Test1      toto     test2      riri
0  0.923249  0.572528  0.845464  0.144891
1  0.020438  0.332540  0.144455  0.741412

cols = [c for c in df.columns if c.lower()[:4] != 'test']

df=df[cols]

print df
       toto      riri
0  0.572528  0.144891
1  0.332540  0.741412
Posted by: Guest on August-12-2021

Code answers related to "remove columns that contain string pandas"

Python Answers by Framework

Browse Popular Code Answers by Language