import numpy as np from pandas import Series,DataFrame#导入包 obj = Series(np.arange(5),index = ['a','b','c','d','e'])#创建Series obj obj Out[2]: a 0 b 1 c 2 d 3 e 4 dtype: int32
new_obj = obj.drop('c')#删除'c' new_obj Out[5]: a 0 b 1 d 3 e 4 dtype: int32
obj Out[6]: a 0 b 1 c 2 d 3 e 4 dtype: int32
obj.drop(['b','d'])#删除'b','d' Out[7]: a 0 c 2 e 4 dtype: int32
data = DataFrame(np.arange(25).reshape(5,5),index = ['bj','tj','heb','sjz','sh'],columns=['one','two','three','four','five'])#创建DataFrame data Out[9]: one two three four five bj 01234 tj 56789 heb 1011121314 sjz 1516171819 sh 2021222324
data.drop(['bj','tj'])#删除某行 Out[10]: one two three four five heb 1011121314 sjz 1516171819 sh 2021222324
data.drop('one',axis=1)#删除列 Out[11]: two three four five bj 1234 tj 6789 heb 11121314 sjz 16171819 sh 21222324