Iterate over the table using a Row instance. If a range is not supplied, *all the rows* in the table are iterated upon - you can also use the :meth:`Table.__iter__` special method for that purpose. If you want to iterate over a given *range of rows* in the table, you
(
self,
start: int | None = None,
stop: int | None = None,
step: int | None = None,
)
| 1849 | return self.read_coordinates(coords, field) |
| 1850 | |
| 1851 | def iterrows( |
| 1852 | self, |
| 1853 | start: int | None = None, |
| 1854 | stop: int | None = None, |
| 1855 | step: int | None = None, |
| 1856 | ) -> Iterator[tableextension.Row]: |
| 1857 | """Iterate over the table using a Row instance. |
| 1858 | |
| 1859 | If a range is not supplied, *all the rows* in the table are iterated |
| 1860 | upon - you can also use the :meth:`Table.__iter__` special method for |
| 1861 | that purpose. If you want to iterate over a given *range of rows* in |
| 1862 | the table, you may use the start, stop and step parameters. |
| 1863 | |
| 1864 | .. warning:: |
| 1865 | |
| 1866 | When in the middle of a table row iterator, you should not |
| 1867 | use methods that can change the number of rows in the table |
| 1868 | (like :meth:`Table.append` or :meth:`Table.remove_rows`) or |
| 1869 | unexpected errors will happen. |
| 1870 | |
| 1871 | See Also |
| 1872 | -------- |
| 1873 | tableextension.Row : the table row iterator and field accessor |
| 1874 | |
| 1875 | Examples |
| 1876 | -------- |
| 1877 | :: |
| 1878 | |
| 1879 | result = [ row['var2'] for row in table.iterrows(step=5) |
| 1880 | if row['var1'] <= 20 ] |
| 1881 | |
| 1882 | .. versionchanged:: 3.0 |
| 1883 | If the *start* parameter is provided and *stop* is None then the |
| 1884 | table is iterated from *start* to the last line. |
| 1885 | In PyTables < 3.0 only one element was returned. |
| 1886 | |
| 1887 | """ |
| 1888 | start, stop, step = self._process_range( |
| 1889 | start, stop, step, warn_negstep=False |
| 1890 | ) |
| 1891 | if (start > stop and 0 < step) or (start < stop and 0 > step): |
| 1892 | # Fall-back action is to return an empty iterator |
| 1893 | return iter([]) |
| 1894 | row = tableextension.Row(self) |
| 1895 | return row._iter(start, stop, step) |
| 1896 | |
| 1897 | def __iter__(self) -> Iterator[tableextension.Row]: |
| 1898 | """Iterate over the table using a Row instance. |