afriedman111
afriedman111

Reputation: 2331

Vaex: getValues / rows from a filtered dataframe

I am trying to filter a dataframe and get the rows that meet the filter criteria. I have been able to get a the first object from the dataframe by using the select function first and then calling the evaluate function to get the value:

    df.select( (df['mycol1'] == filter_val1) & (df['mycol2'] == filter_val2))
    x_axis_name = df.evaluate(df['x_axis_name'], selection=True).chunk(0)[0]
    x_axis_id = df.evaluate(df['x_axis_id'], selection=True)[0]
    y_axis_id = df.evaluate(df['y_axis_id'], selection=True)[0]
    y_axis_name = df.evaluate(df['y_axis_name'], selection=True).chunk(0)[0]

First question: is there a better way to get a row than calling evaluate for each column?

Second question: how do I get a list for all of the rows that meet the filter criteria?

Upvotes: 0

Views: 540

Answers (1)

Joco
Joco

Reputation: 813

Does this fit your usecase:

df_filtered = df[(df['mycol1'] == filter_val1) & (df['mycol2'] == filter_val2)]

Alternatively, if you need to gradually build an expression you are going to use to filter the dataframe, you can also do:

boolean_expression = df['mycol1'] == filter_val1) & (df['mycol2'] == filter_val2)
df_filtered = df.filter(boolean_expression)

Upvotes: 0

Related Questions