【发布时间】:2021-09-05 21:40:33
【问题描述】:
我有一个看起来像这样的熊猫数据框:
col1 col2
0 1 A
1 10 A, B
2 20 B
3 5 C
4 70 A, B, C
现在我想在给定条件下搜索 col2 并相应地选择行。例如:
search_pattern = ["A"] -> Select all rows where A is present [rows 0, 1, 4]
search_pattern = ["A", "B"] -> Select all rows where A is present and B is present [rows 1, 4]
search_pattern = ["B"] -> Select all rows where B is present [rows 1, 2, 4]
【问题讨论】:
标签: python pandas string numpy