You can use a list comprehension to filter the columns in a dataframe based on whether they contain a certain string. Here's an example:
main.py398 chars16 lines
This will output:
main.py108 chars5 lines
In this example, new_df
will contain only the columns that contain the string 'ru'
, which are 'fruit'
and 'shape'
.
You can modify the string in the list comprehension to look for different patterns in the column names.
gistlibby LogSnag