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 :: Range python iterate by 2 
Python :: python positional argument follows keyword argument 
Python :: pandas drop missing values for any column 
Python :: add a list in python 
Python :: python rps 
Python :: code challenges python 
Python :: python remove empty values from list 
Python :: find charechtar index in string python 
Python :: convert pandas dataframe to dict with a column as key 
Python :: opencv loop video 
Python :: python declare variables from dictionary 
Python :: insert row at given position in pandas dataframe 
Python :: python declare variable type array 
Python :: python int to bytes 
Python :: one hot numpy 
Python :: python convert json string to class 
Python :: absolute value in python 
Python :: how to print specific part of a dictionary in python 
Python :: python read excel 
Python :: how to reshape dataframe in python 
Python :: get body from request python 
Python :: views.py django 
Python :: how can i remove random symbols in a dataframe in Pandas 
Python :: initialize a 2d list python 
Python :: tqdm in place 
Python :: scikit learn train test split 
Python :: doomsday fuel foobar 
Python :: change forms labels django 
Python :: rename column in pandas with second row 
Python :: get file in file zip python 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =