In [2]:
import numpy as np
from pandas import Series,DataFrame
import pandas as pd
In [3]:
ser1 = Series(np.arange(3),index=['a','b','c'])
ser1
Out[3]:
a    0
b    1
c    2
dtype: int64
In [4]:
# indexを消すにはdropを使う
ser1.drop('b')
Out[4]:
a    0
c    2
dtype: int64
In [5]:
# DataFrameの場合
dframe1 = DataFrame(np.arange(9).reshape((3,3)),index=['SF','LA','NY'],columns=['pop','size','year'])
dframe1
Out[5]:
pop size year
SF 0 1 2
LA 3 4 5
NY 6 7 8
In [9]:
# indexを指定して、行を削除
dframe1.drop('LA') #, axis=0が省略されている
Out[9]:
pop size year
SF 0 1 2
NY 6 7 8
In [7]:
# 列(カラム)を削除することも可能です。
# その場合、列の軸を示す、axis=1が必要
dframe1.drop('year',axis=1)
Out[7]:
pop size
SF 0 1
LA 3 4
NY 6 7