【发布时间】:2021-10-26 17:52:35
【问题描述】:
我有一个 df,它的单元格中有列表对象:
data['country_code']
0 [IT, IT]
1 [PL, PL]
2 [IT, IT]
3 [IT, IT]
4 [IT, IT]
...
6318 [XX, MT]
6319 [FI, FI]
6320 [XX, XX]
6321 [FI, FI]
6322 [FI, FI]
Name: country_code, Length: 6323, dtype: object
如果data['country_code'] 中的列表将'SK' 或'CZ' 作为第一个或第二个元素,我想过滤数据框data
类似这样的:
data[first element of data['country_code'] == 'SK'or'CZ' or second element of data['country_code'] == 'SK'or'CZ']
在 MongoDB 语法中是:
.find({$or: [{country_code: $elemMatch = 'SK'}, {country_code: $elemMatch = 'CZ'}]})
【问题讨论】:
标签: python pandas list filter conditional-statements