geost.accessor.GeostFrame.select_by_condition#
- GeostFrame.select_by_condition(condition: Any, invert: bool = False) DataFrame[source]#
Do a condition-based selection on the DataFrame or GeoDataFrame: return the rows in the data where the ‘condition’ evaluates to True, see examples below.
- Parameters:
condition (list, pd.Series or array like) – Boolean array like object with locations at which the values will be preserved, dtype must be ‘bool’ and the length must correspond with the length of the data.
invert (bool, optional) – If True, the selection is inverted so rows that evaluate to False will be returned. The default is False.
- Returns:
New DataFrame containing only the data selected by this method.
- Return type:
pd.DataFrame
Examples
Select rows in data that contain a specific value:
>>> selection = data.gst.select_by_condition(data["lith"] == "V")
Or select rows in the data that contain a specific (part of) string or strings:
>>> selection = data.gst.select_by_condition(data["column"].str.contains("foo|bar"))
Or select rows in the data based on multiple conditions:
>>> selection = data.gst.select_by_condition((data["column1"] > 2) & (data["column2] < 1))