pandas Series DataFrame 丢弃指定轴上的项(三)
生活随笔
收集整理的這篇文章主要介紹了
pandas Series DataFrame 丢弃指定轴上的项(三)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.0 刪除Series項
from pandas import Series,DataFrame import numpy as np import pandas as pd obj=Series(np.arange(5),index=['a','b','c','d','e'])obj Out[82]: a 0 b 1 c 2 d 3 e 4 dtype: int32 new_obj=obj.drop('c')new_obj Out[84]: a 0 b 1 d 3 e 4 dtype: int32 obj=Series(np.arange(5),index=['a','b','c','d','e'])obj Out[90]: a 0 b 1 c 2 d 3 e 4 dtype: int32 obj.drop(['d','c']) Out[91]: a 0 b 1 e 4 dtype: int322.0 刪除DataFrame項
data=DataFrame(np.arange(16).reshape((4,4)),index=['ohio','colorado','utah','new york'],columns=['one','two','three','four'])data Out[94]: one two three four ohio 0 1 2 3 colorado 4 5 6 7 utah 8 9 10 11 new york 12 13 14 15?? ??刪除 colorado 和ohio
data.drop(['colorado','ohio']) Out[95]: one two three four utah 8 9 10 11 new york 12 13 14 15 data.drop('two',axis=1) Out[98]: one three four ohio 0 2 3 colorado 4 6 7 utah 8 10 11 new york 12 14 15 data.drop(['two','four'],axis=1) Out[100]: one three ohio 0 2 colorado 4 6 utah 8 10 new york 12 14總結
以上是生活随笔為你收集整理的pandas Series DataFrame 丢弃指定轴上的项(三)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pandas DataFrame 索引
- 下一篇: pandas 索引选取和过滤(四)