import numpy as np
import pandas as pd
from pandas import Series,DataFrame
文章目录
3.1索引
s1=Series(range(1,5),index=list('ABCD'))
s1
A 1
B 2
C 3
D 4
dtype: int64
s1.index
Index(['A', 'B', 'C', 'D'], dtype='object')
- 索引不可修改,否则报错,如下
s1.index['0']='a'
- #但是可以整体换掉
s1.index=list('abcd')
s1
a 1
b 2
c 3
d 4
dtype: int64
索引的删除
-
obj.drop(‘index’,axis=0,inplace=False)默认删除行索引
-
obj.drop(‘column’,axis=1,inplace=False)删除索引列
-
默认都是返回新值,除非 inplace=True
df1 = DataFrame(
np.arange(16).reshape(4,4),
index = list('abcd'),
columns = 'one/two/three/four'.