我将尝试做的是:
错误信息是:
options = ['abc', 'def']
df[any(df['a'].str.startswith(start) for start in options)]
我希望应用过滤器,只保留在“a”列中以给定选项之一开头的条目。
下面的代码可以工作,但我需要它能够使用多个前缀选项……
start = 'abc'
df[df['a'].str.startswith(start)]
错误信息是:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
阅读Series的真值是模糊的。使用a.empty、a.bool()、a.item()、a.any()或a.all(),但还不理解如何操作。