Pandas整数索引

1.整数索引

ser = pd.Series(np.arange(3.))
ser[-1]


Traceback (most recent call last):
File "G:\soft\anaconda\install\lib\site-packages\IPython\core\interactiveshell.py", line 2885, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-22-3cbe0b873a9e>", line 1, in <module>
ser[-1]
File "G:\soft\anaconda\install\lib\site-packages\pandas\core\series.py", line 583, in __getitem__
result = self.index.get_value(self, key)
File "G:\soft\anaconda\install\lib\site-packages\pandas\indexes\base.py", line 1980, in get_value
tz=getattr(series.dtype, 'tz', None))
File "pandas\index.pyx", line 103, in pandas.index.IndexEngine.get_value (pandas\index.c:3332)
File "pandas\index.pyx", line 111, in pandas.index.IndexEngine.get_value (pandas\index.c:3035)
File "pandas\index.pyx", line 159, in pandas.index.IndexEngine.get_loc (pandas\index.c:4018)
File "pandas\hashtable.pyx", line 303, in pandas.hashtable.Int64HashTable.get_item (pandas\hashtable.c:6610)
File "pandas\hashtable.pyx", line 309, in pandas.hashtable.Int64HashTable.get_item (pandas\hashtable.c:6554)
KeyError: -1



2.非整数索引

ser2 = pd.Series(np.arange(3.), index=['a','b','c'])
ser2[-1]


Out[23]: 2.0


3.处理整数索引数据

loc用于轴标签，iloc用于整数标签

ser[:1]
Out[24]:
0    0.0
dtype: float64
ser.loc[:1]
Out[25]:
0    0.0
1    1.0
dtype: float64
ser.iloc[:1]
Out[26]:
0    0.0
dtype: float64



06-23 2475

03-03 4842

09-11 1355

04-19 594

11-19 471

03-24

06-02 1010

01-26 3019

01-10 4275

04-20 1324

Pandas的基础看这一篇足以(有后续)

©️2020 CSDN 皮肤主题: 数字20 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。