Pandas 数据分析-第三章(索引)
pandas的索引对象负责管理周标签和其他元数据,构建Series或者DataFrame诗所用到的任何数组或其他序列的标签都会被转成一个index
举个?
In [84]: obj = pd.Series(range(3),index=list('abc'))
In [85]: obj
Out[85]:
a 0
b 1
c 2
dtype: int64
In [86]: index = obj.index
In [87]: index
Out[87]: Index(['a', 'b', 'c'], dtype='object')
In [88]: index[1:]
Out[88]: Index(['b', 'c'], dtype='object')
In [89]: index[0] = 10
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-89-549e9c5948ff> in <module>
----> 1 index[0] = 10
~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in __setitem__(self, key, value)
3936
3937 def __setitem__(self, key, value):
-> 3938 raise TypeError("Index does not support mutable operations")
3939
3940 def __getitem__(self, key):
TypeError: Index does not support mutable operations
我们创建了一个名为obj的Ser