Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get columns containing string

df2 = df.filter(regex='spike')
print(df2)
Comment

Find column whose name contains a specific string

df.loc[:,df.columns.str.contains("spike")]
#OR
spike_cols =[x for x in df.columns[df.columns.str.contains('spike')]]
#OR
spike_cols = [x for x in df.columns if 'spike' in x]
df[spike_cols]
#To drop spike_cols
df[df.columns.drop(spike_cols)]
#OR
# select columns containing 'spike'
df.filter(like='spike', axis=1)
#OR
df2 = df.filter(regex='spike')


Comment

PREVIOUS NEXT
Code Example
Python :: count items in list 
Python :: psyche 
Python :: count gabarit django 
Python :: python insert object into list 
Python :: find index of pandas column 
Python :: initialize array of natural numbers python 
Python :: pandas datetime.time 
Python :: cv2 yellow color range 
Python :: from django.utils.translation import ugettext_lazy as _ 
Python :: setting a condition for perfect square in python 
Python :: Example XlsxWriter in Python 
Python :: python csv reader 
Python :: how to detect an even number in python 
Python :: check if float is integer python 
Python :: pathlib current directory 
Python :: plotly update legend title 
Python :: get all h1 beautifulsoup 
Python :: request.body django 
Python :: python live video streaming flask 
Python :: http.server python 
Python :: mob psycho 100 
Python :: python typed list 
Python :: adding numbers using python function 
Python :: return max repeated value in list 
Python :: dict.fromkeys with list as value 
Python :: python convert dictionary to pandas dataframe 
Python :: python datetime no milliseconds 
Python :: charcodeat python 
Python :: merge on row number python 
Python :: pandas df row count 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =