amol- commented on a change in pull request #12010: URL: https://github.com/apache/arrow/pull/12010#discussion_r773255388
########## File path: python/pyarrow/table.pxi ########## @@ -1838,6 +1953,36 @@ cdef class Table(_PandasConvertible): return ordered_dict(entries) + def to_pylist(self): + """ + Convert the Table to a list of dictionaries. + + Returns + ------- + list + + Examples + -------- + >>> import pyarrow as pa + >>> table = pa.table([ + ... pa.array([1, 2]), + ... pa.array(["a", "b"]) + ... ], names=["int", "str"]) + >>> table.to_pylist() + [{'int': [1, 2]}, {'str': ['a', 'b']}] + """ + cdef: + size_t i + size_t num_columns = self.table.num_columns() + list entries = [] + ChunkedArray column + + for i in range(num_columns): + column = self.column(i) + entries.append({self.field(i).name: column.to_pylist()}) Review comment: `self.itercolumns` should do the trickk for you, also the returned columns has `_name` attribute, so you don't need to look into the field. Last I suggest we use a list comprehension to speed up the building -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org