其实之前在python 库整理:pandas_UQI-LIUWJ的博客-CSDN博客我们已经遇到了,这里系统地说一下
1 特点- 不可修改的数组
- 有序
- 支持可重复的key
inA=pd.Index([1,1,2,3,4]) inA #Int64Index([1, 1, 2, 3, 4], dtype='int64')
inA[2]=2 ''' TypeError: Index does not support mutable operations '''2 函数
| & | 右连接(返回包括右Index中的所有记录和左Index中连接字段相等的记录) |
| | | 并集(左Index有的都有) |
| ^ | 两个Index不同的部分 |
可以修改原来dataframe的Index
inA=pd.Index([1,1,2,3,4])
inB=pd.Index([2,3,3,5,1])
a=pd.DataFrame(np.arange(25).reshape(5,5))
a
'''
0 1 2 3 4
0 0 1 2 3 4
1 5 6 7 8 9
2 10 11 12 13 14
3 15 16 17 18 19
4 20 21 22 23 24
'''
a.index=inA
a.columns=inB
a
'''
2 3 3 5 1
1 0 1 2 3 4
1 5 6 7 8 9
2 10 11 12 13 14
3 15 16 17 18 19
4 20 21 22 23 24
'''



