Files
aiomql/Untitled1.ipynb
T
2024-08-29 06:36:09 +01:00

17 KiB

In [1]:
import pandas as pd
import numpy as np
from pandas import DataFrame, Series
In [2]:
rs = DataFrame({0: range(10, 101, 10), 1: range(10, 20), 2: range(20, 40, 2), "symbols": [chr(i) for i in [65]*5 + [68]*5]})
In [6]:
rs[rs.symbols == 'A']
Out [6]:
0 1 2 symbols
0 10 10 20 A
1 20 11 22 A
2 30 12 24 A
3 40 13 26 A
4 50 14 28 A
In [71]:
ind = rs[rs['symbols'] != 'A'].iloc[0].index.name
rs.loc[ind]
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[71], line 2
      1 ind = rs[rs['symbols'] != 'A'].iloc[0].index.name
----> 2 rs.loc[ind]

File ~\OneDrive - UBA\Documents\Personal\VS\aiomql\venv\Lib\site-packages\pandas\core\indexing.py:1191, in _LocationIndexer.__getitem__(self, key)
   1189 maybe_callable = com.apply_if_callable(key, self.obj)
   1190 maybe_callable = self._check_deprecated_callable_usage(key, maybe_callable)
-> 1191 return self._getitem_axis(maybe_callable, axis=axis)

File ~\OneDrive - UBA\Documents\Personal\VS\aiomql\venv\Lib\site-packages\pandas\core\indexing.py:1431, in _LocIndexer._getitem_axis(self, key, axis)
   1429 # fall thru to straight lookup
   1430 self._validate_key(key, axis)
-> 1431 return self._get_label(key, axis=axis)

File ~\OneDrive - UBA\Documents\Personal\VS\aiomql\venv\Lib\site-packages\pandas\core\indexing.py:1381, in _LocIndexer._get_label(self, label, axis)
   1379 def _get_label(self, label, axis: AxisInt):
   1380     # GH#5567 this will fail if the label is not present in the axis.
-> 1381     return self.obj.xs(label, axis=axis)

File ~\OneDrive - UBA\Documents\Personal\VS\aiomql\venv\Lib\site-packages\pandas\core\generic.py:4301, in NDFrame.xs(self, key, axis, level, drop_level)
   4299             new_index = index[loc]
   4300 else:
-> 4301     loc = index.get_loc(key)
   4303     if isinstance(loc, np.ndarray):
   4304         if loc.dtype == np.bool_:

File ~\OneDrive - UBA\Documents\Personal\VS\aiomql\venv\Lib\site-packages\pandas\core\indexes\range.py:417, in RangeIndex.get_loc(self, key)
    415         raise KeyError(key) from err
    416 if isinstance(key, Hashable):
--> 417     raise KeyError(key)
    418 self._check_indexing_error(key)
    419 raise KeyError(key)

KeyError: None
In [44]:
rs
Out [44]:
0 1 2 symbols
0 10 10 20 A
1 20 11 22 A
2 30 12 24 A
3 40 13 26 A
4 50 14 28 A
5 60 15 30 D
6 70 16 32 D
7 80 17 34 D
8 90 18 36 D
9 100 19 38 D
In [31]:
rs.index.get_loc(rs[rs.index <= 31].index)
---------------------------------------------------------------------------
InvalidIndexError                         Traceback (most recent call last)
Cell In[31], line 1
----> 1 rs.index.get_loc(rs[rs.index <= 31].index)

File ~\OneDrive - UBA\Documents\Personal\VS\aiomql\venv\Lib\site-packages\pandas\core\indexes\range.py:418, in RangeIndex.get_loc(self, key)
    416 if isinstance(key, Hashable):
    417     raise KeyError(key)
--> 418 self._check_indexing_error(key)
    419 raise KeyError(key)

File ~\OneDrive - UBA\Documents\Personal\VS\aiomql\venv\Lib\site-packages\pandas\core\indexes\base.py:6059, in Index._check_indexing_error(self, key)
   6055 def _check_indexing_error(self, key):
   6056     if not is_scalar(key):
   6057         # if key is not a scalar, directly raise an error (the code below
   6058         # would convert to numpy arrays and raise later any way) - GH29926
-> 6059         raise InvalidIndexError(key)

InvalidIndexError: RangeIndex(start=0, stop=10, step=1)
In [73]:
rs.index
Out [73]:
Index([20, 22, 24, 26, 28, 30, 32, 34, 36, 38], dtype='int64', name=2)
In [28]:
g = rs[rs.index <= 31].iloc[-1]
In [87]:
rs.index[0]
Out [87]:
np.int64(20)
In [114]:
t = list(range(30))
t[25:30]
Out [114]:
[25, 26, 27, 28, 29]
In [121]:
t[6: 10]
Out [121]:
[6, 7, 8, 9]
In [126]:
p = 0 or None
print(p)
None
In [ ]: