Python:如何使用系列中的值过滤Pandas DataFrame?
上下文
我目前正在处理一些数据并遇到问题。 我想使用系列中的值过滤熊猫数据框。 但是,这总是会引发以下错误:
valueerror:系列的真实价值是模棱两可的。使用A.Empty,A.Bool(),A.Item(),a.any()或a.all()。
代码
# DataFrame
userID (Int) | startTS (Int) | endTS (Int) | placeID (String)
# Group Data into Subgroups, one for each User.
stayGroup = stayData.groupby('userID')
for userID, data in stayGroup:
for index, row in data.iterrows():
# Stays starting during this Stay.
staysA = data[row['startTS'] < data['startTS'] < row['endTS']]
# Stays ending during this Stay.
staysB = data[row['startTS'] < data['endTS'] < row['endTS']]
# Stays starting before and ending after this Stay.
staysC = data[(row['startTS'] >= data['startTS']) & (row['endTS'] <= data['endTS'])]
问题
有人知道这个错误是什么意思以及我如何解决? 非常感谢您提前提供的帮助!
Context
I am currently processing some data and encountered a problem.
I would like to filter a Pandas DataFrame using Values from a Series.
However, this always throws the following Error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Code
# DataFrame
userID (Int) | startTS (Int) | endTS (Int) | placeID (String)
# Group Data into Subgroups, one for each User.
stayGroup = stayData.groupby('userID')
for userID, data in stayGroup:
for index, row in data.iterrows():
# Stays starting during this Stay.
staysA = data[row['startTS'] < data['startTS'] < row['endTS']]
# Stays ending during this Stay.
staysB = data[row['startTS'] < data['endTS'] < row['endTS']]
# Stays starting before and ending after this Stay.
staysC = data[(row['startTS'] >= data['startTS']) & (row['endTS'] <= data['endTS'])]
Question
Does anyone have an idea what's this error means and how I can solve it?
Thanks a lot for your assistance in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是
row ['startts']&lt; data ['startts']&lt;行['endts']
,您可以使用Problem is
row['startTS'] < data['startTS'] < row['endTS']
, you can use