pandas笔记: Index对象

pandas笔记: Index对象,第1张

其实之前在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不同的部分

3 作用

可以修改原来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
'''

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/884147.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-14
下一篇2022-05-14

发表评论

登录后才能评论

评论列表(0条)

    保存