python去掉字符串开头的零_Python / Pandas-删除以字符串开头的列
生活随笔
收集整理的這篇文章主要介紹了
python去掉字符串开头的零_Python / Pandas-删除以字符串开头的列
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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
總結(jié)
以上是生活随笔為你收集整理的python去掉字符串开头的零_Python / Pandas-删除以字符串开头的列的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 混合高斯模型_EM算法求解高斯混合模型(
- 下一篇: python正则查找_python正则查