Search code examples
pythonpandasdataframedatatable

How to iterate over rows of a Frame in DataTable


With pandas I usually iterate the rows of a DataFrame with itertuples or iterrows. How can I do this kind of iteration on a Frame from Python DataTable?

Exemple of Pandas iteration that I need:

for row in df_.itertuples():
    print(row)

Solution

  • You can use .to_tuples to achieve row iteration.

    from datatable import dt
    data = {"A": [1, 2, 3, 4, 5],
            "B": [4, 5, 6, 7, 8],
            "C": [7, 8, 9, 10, 11],
            "D": [5, 7, 2, 9, -1]}
    
    DT = dt.Frame(data)
    
    for row in DT.to_tuples():
            print(row)