Issue
I need to find unique name, whose age=2 and and cond=9 using python pandas?
name | age | cond | cc |
---|---|---|---|
a | 2 | 9 | 3 |
b | 2 | 8 | 2 |
c | 3 | 9 | 1 |
a | 2 | 9 | 6 |
Solution
The Pandas query function allows for SQL-like queries to filter a data frame. Then use unique() on the results to return the unique name.
rows = df.query('age == 2 and cond == 9')
print(rows["name"].unique())
For more query examples, see here.
Answered By - CodeMonkey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.