pandas 数据框的 if 条件
我对此代码有疑问,我不知道我是否选择了正确的数据帧:
if (df_total[(df_total["name"] == "STREET 292") & (df_total["free_motobikes"] != 0) & (df_total["HOUR"] == 7) & (df_total["MINUTES"]<= 50)]):
print("User can take a motobike at STREET 292 by aprox. 7:50 am ")
elif (df_total[(df_total["name"] == "STREET 6") & (df_total["empty_slots"] != 0) & (df_total["HOUR"] <= 8)]):
print("User can park the motobike at AV. DE LA CATEDRAL, 6 by aprox 8:00 am")
else:
print("User cannot take a motobike neither park it")
输出:
ValueError
def __nonzero__(self):
1537 raise ValueError(
\-\> 1538 f"The truth value of a {type(self).__name__} is ambiguous. "
1539 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
1540 )
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我希望程序检查这两个条件,以便知道用户是否可以在这段时间内骑摩托车。
I have a doubt regarding this code and I don't know if I'm selecting correct the dataframe:
if (df_total[(df_total["name"] == "STREET 292") & (df_total["free_motobikes"] != 0) & (df_total["HOUR"] == 7) & (df_total["MINUTES"]<= 50)]):
print("User can take a motobike at STREET 292 by aprox. 7:50 am ")
elif (df_total[(df_total["name"] == "STREET 6") & (df_total["empty_slots"] != 0) & (df_total["HOUR"] <= 8)]):
print("User can park the motobike at AV. DE LA CATEDRAL, 6 by aprox 8:00 am")
else:
print("User cannot take a motobike neither park it")
Output:
ValueError
def __nonzero__(self):
1537 raise ValueError(
\-\> 1538 f"The truth value of a {type(self).__name__} is ambiguous. "
1539 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
1540 )
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I want that the program check both conditions in order to know if the user could take a motorbike in this frame of time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用:
Use: