Как перебирать повторяющиеся строки? - PullRequest
0 голосов
/ 07 октября 2019

Итератор recarray по умолчанию, кажется, работает над столбцами. Есть ли аналог pandas'es iterrows / itertuples, который повторяет представления строк?

1 Ответ

0 голосов
/ 07 октября 2019
In [102]: np.dtype('O,O,O')                                                     
Out[102]: dtype([('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
In [103]: dt = np.dtype('O,O,O')                                                
In [104]: np.recarray((4,), dt)                                                 
Out[104]: 
rec.array([(None, None, None), (None, None, None), (None, None, None),
           (None, None, None)],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
In [105]: arr = np.recarray((4,), dt)                                           
In [106]: arr                                                                   
Out[106]: 
rec.array([(None, None, None), (None, None, None), (None, None, None),
           (None, None, None)],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
In [107]: arr.f0                                                                
Out[107]: array([None, None, None, None], dtype=object)
In [108]: arr['f0']                                                             
Out[108]: array([None, None, None, None], dtype=object)
In [109]: for i in arr: print(repr(i))                                          
(None, None, None)
(None, None, None)
(None, None, None)
(None, None, None)
In [110]: arr = np.recarray((4,1), dt)                                          
In [111]: arr                                                                   
Out[111]: 
rec.array([[(None, None, None)],
           [(None, None, None)],
           [(None, None, None)],
           [(None, None, None)]],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
In [112]: for i in arr: print(repr(i))                                          
rec.array([(None, None, None)],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
rec.array([(None, None, None)],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
rec.array([(None, None, None)],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
rec.array([(None, None, None)],
          dtype=[('f0', 'O'), ('f1', 'O'), ('f2', 'O')])
...