小编Mal*_*hus的帖子

使用Python中缀语法将"管道"输出从一个函数输出到另一个函数

我正在尝试使用Python/Pandas(作为学习练习)粗略地复制R中的dplyr包.我坚持的是"管道"功能.

在R/dplyr中,这是使用管道运算符完成的%>%,其中x %>% f(y)相当于f(x, y).如果可能,我想使用中缀语法复制它(参见此处).

为了说明,请考虑以下两个功能.

import pandas as pd

def select(df, *args):
    cols = [x for x in args]
    df = df[cols]
    return df

def rename(df, **kwargs):
    for name, value in kwargs.items():
        df = df.rename(columns={'%s' % name: '%s' % value})
    return df
Run Code Online (Sandbox Code Playgroud)

第一个函数采用数据帧并仅返回给定的列.第二个采用数据帧,并重命名给定的列.例如:

d = {'one' : [1., 2., 3., 4., 4.],
     'two' : [4., 3., 2., 1., 3.]}

df = pd.DataFrame(d)

# Keep only the 'one' column.
df …
Run Code Online (Sandbox Code Playgroud)

python pipeline infix-notation

25
推荐指数
4
解决办法
1万
查看次数

根据滚动位置更改div内容

我希望在另一个Stack Exchange帖子中使用代码提供一些帮助.以下是javascript:

$(window).on("scroll resize", function(){
    var pos=$('#date').offset();
    $('.post').each(function(){
        if(pos.top >= $(this).offset().top && pos.top <= $(this).next().offset().top)
        {
            $('#date').html($(this).html()); //or any other way you want to get the date
            return; //break the loop
        }
    });
});

$(document).ready(function(){
  $(window).trigger('scroll'); // init the value
});
Run Code Online (Sandbox Code Playgroud)

我在我自己的网站上实现了它:http://peterwoyzbun.com/newscroll/scroll.html.当滚动位置到达某个点时,框中的信息会发生变化.目前,不断变化的内容直接来自div".post".也就是说,当用户滚动到给定的".post"时,固定灰色框加载".post"中的内容.

我想要做的是让灰色框显示用户当前看到的内容.因此,当用户到达div"content1"时,灰色框显示"content1"的文本描述.也许当达到"content1"时,div"description1"在灰盒子中变得不隐藏?

任何帮助将不胜感激.谢谢!

html javascript jquery

5
推荐指数
1
解决办法
6592
查看次数

Python pip安装错误(羽毛格式)

我一直试图在过去几天安装Python的Feather文件格式(https://pypi.python.org/pypi/feather-format),但没有运气.我在Windows 10上使用Anaconda2.当我尝试pip install feather-format时出现以下错误:

 Collecting feather-format
      Using cached feather-format-0.2.0.tar.gz
    Requirement already satisfied (use --upgrade to upgrade): cython>=0.21 in c:\users\pete\anaconda2\lib\site-packages (from feather-format)
    Building wheels for collected packages: feather-format
      Running setup.py bdist_wheel for feather-format ... error
      Complete output from command C:\Users\pete\Anaconda2\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\pete\\appdata\\local\\temp\\pip-build-g4egjo\\feather-format\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d c:\users\pete\appdata\local\temp\tmp1gwqlopip-wheel- --python-tag cp27:
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-2.7
      creating build\lib.win-amd64-2.7\feather
      copying feather\api.py -> build\lib.win-amd64-2.7\feather
      copying feather\compat.py -> build\lib.win-amd64-2.7\feather
      copying feather\version.py -> build\lib.win-amd64-2.7\feather …
Run Code Online (Sandbox Code Playgroud)

c++ python

2
推荐指数
1
解决办法
2076
查看次数

标签 统计

python ×2

c++ ×1

html ×1

infix-notation ×1

javascript ×1

jquery ×1

pipeline ×1