pythondatatablepy-datatable

subset datatable by column


Trying to subset a datatabl a couple different ways:

DT1 = dt.Frame(A=range(5))

DT1[f.A > 2] ## select rows where A greater than 2

DT1[DT1['A'] > 2] ## select rows where A greater than 2

DT1[DT1['A'] in 2] ## select rows where A equal to 2

However getting errors on all of these.

What would the correct syntax be?


Solution

  • If you want to select rows of a Frame based on some condition, then the syntax for that is

    DT1[f.A > 2, :]
    

    So, what you have written is almost correct, except that it misses the column selector part :.

    You can check the tutorial for different kinds of column/row selection at https://datatable.readthedocs.io/en/latest/manual/select_and_filter_data.html