In order to subset columns in pandas dataframe based on the given string, you can use the filter()
function. The filter(regex=”String”)
function returns the columns that contain the given string.
Here's an example code:
main.py313 chars11 lines
This will output:
main.py70 chars5 lines
Alternatively, if you want to subset columns that exactly match the given string, you can use the loc
function as follows:
main.py51 chars2 lines
This also produces the same output as above.
gistlibby LogSnag