首页 \ 问答 \ Python,Pandas,倒转扩展窗口(Python, Pandas, inverted expanding window)

Python,Pandas,倒转扩展窗口(Python, Pandas, inverted expanding window)

让我们考虑以下系列:

s=pd.Series(data=[100, 110, 120, 150, 110, 90, 80, 70, 90, 95])

我遍历每个项目并执行以下操作:

for i in range(len(s)):
    m=max(s[i]-s[i:])

基本上比较每个项目与后面的所有项目,并检索最大值。

我可以这样做:

r=[]
for i in range(len(s)):
    m=max(s[i]-s[i:])
    r.append(m)

result=pd.Series(r)

但我有这样的感觉,这将是一个滚动窗口可以做的事情? 我试图让我的代码更清洁一点,并开始阅读和探索滚动功能,但我还没办法,只能用手指。 这个想法看起来像是一个倒转的扩展函数(即它随着数据的传递需要越来越少的数据)?

如果有人有关于如何使用滚动/展开窗口重新设置代码格式的想法,请告诉我。


Lets consider the following Series:

s=pd.Series(data=[100, 110, 120, 150, 110, 90, 80, 70, 90, 95])

I iterate over each item and perform the following operation:

for i in range(len(s)):
    m=max(s[i]-s[i:])

Basically comparing each item with all items that follow, and retrieving the max.

I can do that with:

r=[]
for i in range(len(s)):
    m=max(s[i]-s[i:])
    r.append(m)

result=pd.Series(r)

But I had the feeling that this would be something that a rolling window could do? I am trying to make my code a bit cleaner and was just starting reading and exploring about the rolling function, but i cannot yet but my finger on it. This idea seems like a inverted expanding function (i.e. it takes less and less data as it goes down the data)?

If someone has ideas about how to reformat the code using rolling / expanding windows, please let me know.


原文:https://stackoverflow.com/questions/47643594
更新时间:2023-11-27 07:11

最满意答案

将您的jQuery更改为:

$(document).ready(function(){
   $("div.portfolio-img").hover(function(){
         $(this).toggleClass("portfolio-img-hover");
         $(this).find("h5.excerpt-title").toggleClass("excerpt-title-hover");
         $(this).find("p.portfolio-excerpt").toggleClass("portfolio-excerpt-hover"); 
      }
   );
});

并在你的.portfolio-img-hover{}交换你的.portfolio-img-hover{}portfolio-img{}的地方。

在这里尝试一下: jsFiddle


Change your jQuery to this:

$(document).ready(function(){
   $("div.portfolio-img").hover(function(){
         $(this).toggleClass("portfolio-img-hover");
         $(this).find("h5.excerpt-title").toggleClass("excerpt-title-hover");
         $(this).find("p.portfolio-excerpt").toggleClass("portfolio-excerpt-hover"); 
      }
   );
});

and swap places on your .portfolio-img-hover{} and portfolio-img{} in your css.

Try it out here: jsFiddle

相关问答

更多
  • 使用toggleClass方法时,您不需要在类名前面加上句点(。)。 $(document).ready(function () { $('.css-label-notick').on('click', function (e) { $(this).toggleClass("css-label-tick"); }); }); 工作示例: http : //jsfiddle.net/xno5hb34/3/ While using toggle ...
  • 你似乎错过了# $("ptVerbiage") => $("#ptVerbiage") 和 不是.val()而是.text() ; as。用于输入 应该是这样的 $( "#ptVerbiage" ).hover(function() { $(this).text('yep!'); }, function() { $(this).text('nope!'); }); http://jsfiddle.net/n9sq7x8y/4/ You seem to be missing a # $("ptVer ...
  • 将您的jQuery更改为: $(document).ready(function(){ $("div.portfolio-img").hover(function(){ $(this).toggleClass("portfolio-img-hover"); $(this).find("h5.excerpt-title").toggleClass("excerpt-title-hover"); $(this).find("p.portfolio-ex ...
  • 要显示的元素位于搁置元素的“顶部”的事实造成了麻烦。 作为替代方案,我建议只在悬停时显示元素,当它们被遮挡时隐藏它们: $('.folder-items a').hover(function(){ $(this).siblings('.file-hover').show(); }).siblings('.file-hover').hover( function() { }, function() { $(this).hide(); } ); 更新:这不是一个完美的解决方案。 如果你 ...
  • 你太过于复杂,并且很难做到。 为了解决您的问题,您应该动态委派您的点击,因为您无缘无故地动态重建按钮(通过使用.html() )! 因此,quickfix将使用.on()方法和动态事件委派 $("staticParent").on("eventName", "dynamicChild", function() { 例: function mobileToggle() { if ($(".menu-list-section").css("display") !== "none") { $(" ...
  • 我建议使用jQuery .slideToggle('slow'); 而不是.toggle('slow','swing'); 。 它基本上会做同样的事情,但它会向下滑动而不是从左向右滑动。 jQuery .toggle(); 应该是从左到右 // Show hide on click function showNavi() { $("#navigationin").slideToggle('slow'); $('#chevron').toggleClass('rotate180'); ...
  • 切换不会像你认为的那样做。 切换用于隐藏或显示元素。 由于您在加载页面后立即运行该功能,因此立即使用一个漂亮的小动画隐藏该按钮。 http://api.jquery.com/toggle/ 看看这是否符合您的要求: var buttonState = 0; $(document).ready(function() { $('#cm_now').click(function() { if(buttonState == 0) { $('.search_ ...
  • jquery hover()函数将两个函数作为参数:handleIn和HandleOut。 点击没有。 因此,您必须使用单独的变量跟踪点击的状态。 例如: var sidebarFloat = $('.sidebar').css('float'); var toggled = false; $('.sidebar').click(function() { if (toggled) { sidebarFloat = $(this).css('float'); if (s ...
  • 您忘了关闭第二个打开的script标记: