Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

remove columns that contain string pandas

df = df[df.columns.drop(list(df.filter(regex='Test')))]
Comment

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
Comment

PREVIOUS NEXT
Code Example
Python :: how to set the size of a kivy window bigger than screen 
Python :: frozen 
Python :: Django delete a session value 
Python :: python string: .join() 
Python :: spacy get number of tokens 
Python :: while not command in python 
Python :: if equal to key return value python 
Python :: python get type of variable 
Python :: python dictionary key in range 
Python :: python generate dictionary in loop 
Python :: Python Requests Library Delete Method 
Python :: pygame keys keep pressing 
Python :: join 3 dataframes by index python 
Python :: how to save frames in form of video in opencv python 
Python :: python even or odd 
Python :: django loginview 
Python :: check if object is array like python 
Python :: python delete from dictionary pop 
Python :: python form html 
Python :: instance method in python 
Python :: remove all parentheses from string python 
Python :: what is index in list in python 
Python :: python to exe online 
Python :: python list extend() 
Python :: scan python 
Python :: python logging level 
Python :: Count the number of cells that contain a specific value in a pandas dataframe python 
Python :: python program to reverse a list 
Python :: find the sitepckages for anaconda 
Python :: assert in python 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =