Python中pandas dataframe删除一行或一列:drop函数详解
用法:DataFrame.drop(labels=None,axis=0,index=None,columns=None,inplace=False)
在这里默认:axis=0,指删除index,因此删除columns时要指定axis=1;
inplace=False,默认该删除操作不改变原数据,而是返回一个执行删除操作后的新dataframe;
inplace=True,则会直接在原数据上进行删除操作,删除后就回不来了。
例子:
>>>df=pd.DataFrame(np.arange(12).reshape(3,4),columns=['A','B','C','D']) >>>df ABCD 00123 14567 2891011 #Dropcolumns,下面两种方法等价 >>>df.drop(['B','C'],axis=1) AD 003 147 2811 >>>df.drop(columns=['B','C']) AD 003 147 2811 #Droprowsbyindex >>>df.drop([0,1]) ABCD 2891011
以上这篇Python中pandasdataframe删除一行或一列:drop函数详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。