series.where 包含列表的系列

series.where on a series containing lists

我有一个名为 hours_by_analysis_date 的系列,其中索引是 datetimes,值是一个整数列表。例如:

Index      |
01-01-2000 | [1, 2, 3, 4, 5]
01-02-2000 | [2, 3, 4, 5, 6]
01-03-2000 | [1, 2, 3, 4, 5]

我想要 return 值为 [1, 2, 3, 4, 5] 的所有索引,所以它应该 return 01-01-200001-03-2000

我试过 hours_by_analysis_date.where(fh_by_analysis_date==[1, 2, 3, 4, 5]),但它给了我错误:

{ValueError} lengths must match to compare

比较两个类数组对象和每个元素的相等性测试之间的混淆。

您可以使用 apply:

hours_by_analysis_date.apply(lambda elem: elem == [1,2,3,4,5])