I have a dataframe like this
id 2013 Profits 2001 Revenues 1999 Assets...
31 xxxx xxxx xxxx
...
I want to drop the columns that do not start with '201' (I only want to keep the data 2010 and forward).
How can I do that?
解决方案df.filter(like='201')
2013 Profits
id
31 xxxx
As pointed out by @StevenLaan using like will include some columns that have the pattern string somewhere else in the columns name. We can ensure that we only get columns that begin with the pattern string by using regex instead.
df.filter(regex='^201')
2013 Profits
id
31 xxxx