如下所示:
import numpy as npimport pandas as pdfrom pandas import Series,DataFrame一、drop方法:产生新对象
1.Series
o = Series([1,3,4,7],index=['d','c','b','a'])print(o.drop(['d','b']))c 3a 7dtype: int642.DataFrame
data = {'水果':['苹果','梨','草莓'], '数量':[3,2,5], '价格':[10,9,8]}df = DataFrame(data)print(df) 价格 数量 水果0 10 3 苹果1 9 2 梨2 8 5 草莓删除第0轴(行)
print(df.drop([0,2])) 价格 数量 水果1 9 2 梨删除第1轴(列)
print(df.drop(['价格','数量'],axis=1)) 水果0 苹果1 梨2 草莓二、del关键字:在原对象上删除
1.Series
del o['a']print(o)d 1c 3b 4dtype: int642.DataFrame
del df['价格']print(df) 数量 水果0 3 苹果1 2 梨2 5 草莓以上这篇Pandas:Series和DataFrame删除指定轴上数据的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。