首页 \ 问答 \ 长熊猫逻辑运算(Long pandas logic operation)

长熊猫逻辑运算(Long pandas logic operation)

有没有更好的方法来编写这个长pandas逻辑运算? 我只列出了下面的几个例子,但实际上有更多的检查。 这样做的工作,但我觉得可能有一种更清洁的方式来表达这个操作。 如果您对这些数据感到好奇,那就是纽约出租车数据。任何建议都表示赞赏。

mask = (df.Fare_amount >= 2.5) & \
       (df.Total_amount >= 2.5) & \
       (df.Tip_amount >= 0) & \
       (df.Tolls_amount >= 0) & \
       (df.Extra >= 0) & \
       (df.Trip_distance > 0) & \
       (df.Passenger_count.between(1, 5))

# I actually have some more checks here like these above....

new_df = df[mask].copy()

Is there a better way to write this long pandas logic operation? I only listed a few examples below but actually have a lot more checks. This does the job but I feel like there might be a cleaner way to express this operation. In case if you are curious about this data, it is NYC taxi data Any advice is appreciated.

mask = (df.Fare_amount >= 2.5) & \
       (df.Total_amount >= 2.5) & \
       (df.Tip_amount >= 0) & \
       (df.Tolls_amount >= 0) & \
       (df.Extra >= 0) & \
       (df.Trip_distance > 0) & \
       (df.Passenger_count.between(1, 5))

# I actually have some more checks here like these above....

new_df = df[mask].copy()

原文:https://stackoverflow.com/questions/43312532
更新时间:2023-03-31 10:03

最满意答案

尝试指定如下,

return RedirectToAction(Url.Action("Edit", "Account") + "#/tabs-2");

即使您使用此功能,也不确定是否会选中该选项卡。 由于仅根据查询字符串上没有的事件选择选项卡。 因此,最好将新查询字符串创建为“tab”或“active”,或者根据需要创建,并传递活动选项卡的值。

    return RedirectToAction("Edit", routeValues: new { controller = "Account", activetab = "tabs-2" });

然后使用jquery,在文档加载时,您可以通过适当的选择器自行触发选项卡的单击事件。

试试吧,

$("a[href='#tabs-2']").trigger("click");

Try specifying as below,

return RedirectToAction(Url.Action("Edit", "Account") + "#/tabs-2");

Even if you get this working, not sure the tab will be selected. Since the tabs will only be selected based on events not on the query string. So it is preferred to create a new query string as 'tab' or 'active' or as you like and pass the value of active tab.

    return RedirectToAction("Edit", routeValues: new { controller = "Account", activetab = "tabs-2" });

Then using jquery, on document load you may trigger the click event for the tab by appropriate selector by yourself.

Try as,

$("a[href='#tabs-2']").trigger("click");

相关问答

更多
  • 一个简单的解决方案是将parenot url设置为像http://origilal.url#tab3这样的东西,并像你一样设置reload()。 然后,在init js函数中,解析window.location以检查url中提到的选项卡,然后选择它。 A simple solution will be to set the paren't url to something like http://origilal.url#tab3 and the reload() like you do. Afterwar ...
  • 我终于自己想出来了。 仍然对我收到的缺乏帮助感到生气。 对于我这样做的形式:
    ...
    然后我添加了一个只执行该工作的脚本,因为它是最后一个选项卡,但可以修改: