vice.dataframe.filter¶
Obtain a copy of the dataframe whose elements satisfy a filter. Only applies to dataframes whose values are all array-like.
Signature: x.filter(key, relation, value)
New in version 1.1.0.
Parameters¶
- x
dataframe
An instance of this class
- key
str
[case-insensitive] The dataframe key to filter based on
- relation
str
Either ‘<’, ‘<=’, ‘=’, ‘==’, ‘!=’, ‘>=’, or ‘>’, denoting the relation to filter based on.
- valuereal number
The value to filter based on.
Returns¶
- filtered
dataframe
A dataframe whose elements are only those which satisfy the specified filter. This will always be an instance of the base class, even if the function called with an instance of a derived class.
Raises¶
- KeyError
Key is not in the dataframe
- ValueError
Invalid relation
Example Code¶
>>> import vice
>>> example = vice.dataframe({
"a": [1, 2, 3],
"b": [4, 5, 6],
"c": [7, 8, 9]})
>>> example
vice.dataframe{
a --------------> [1, 2, 3]
b --------------> [4, 5, 6]
c --------------> [7, 8, 9]
}
>>> example.filter("a", "=", 2)
vice.dataframe{
a --------------> [2]
b --------------> [5]
c --------------> [8]
}
>>> example.filter("c", "<=", 8)
vice.dataframe{
a --------------> [1, 2]
b --------------> [4, 5]
c --------------> [7, 8]
}