小编par*_*ent的帖子

获取多索引中级别的最后一个元素

我有一个这种格式的数据框:

a   b   x
1   1   31
1   2   1
1   3   42
1   4   423
1   5   42
1   6   3
1   7   44
1   8   65437
1   9   73
2   1   5656
2   2   7
2   3   5
2   4   5
2   5   34
Run Code Online (Sandbox Code Playgroud)

ab是索引,x是值。

我想行1 9 732 5 34,换句话说,该级别的最后一排。

我已经弄乱了.loc,.iloc.xs一个小时,但我无法让它工作。我该怎么做呢?

python numpy multi-index dataframe pandas

6
推荐指数
1
解决办法
1461
查看次数

Typeahead调用函数.val .open .close等会抛出错误

我奋力调用像typeahead.js功能val,open,close,等.

typeahead在输入元素上正常工作,因为它显示条目但是当我尝试调用任何typeahead函数时,我收到此错误:

Uncaught Error: one of local, prefetch, or remote is requiredmessage: "one of local, prefetch, or remote is required
Run Code Online (Sandbox Code Playgroud)

我的初始化代码如下:

var currentMedicalAid;

var medicalAidList = $('#medicalAidList');


var medicalAidengine = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('MedicalAid1'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    limit: 5,
    prefetch: {
        url: '/api/Search/GetMedicalAidList',
    }
});


medicalAidengine.initialize();


medicalAidList.typeahead(null, {
    name: 'MedicalAid1',
    displayKey: 'MedicalAid1',
    // `ttAdapter` wraps the suggestion engine in an adapter that
    // is compatible with the typeahead jQuery plugin
    source: medicalAidengine.ttAdapter()
}).blur(function () { …
Run Code Online (Sandbox Code Playgroud)

javascript typeahead.js twitter-typeahead

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

如何在序言中正确表达不等式?

TL;DR: sibling(a,X)成功回答X = a,但sibling(a,a)失败。


我有以下 Prolog 文件:

children(a, c).
children(a, d).
children(b, c).
children(b, d).

sibling(X, Y) :-
   X \== Y, A \== B,
   children(X, A), children(X, B),
   children(Y, A), children(Y, B).
Run Code Online (Sandbox Code Playgroud)

对我来说似乎很清楚,如果他们的父母相同,那么两个人就是兄弟姐妹。此外,一个人不是他们自己的兄弟姐妹。

但是当我尝试在 GNU Prolog 上运行一些查询时,我得到了一些奇怪的结果:

| ?- sibling(a, b).

true ? a

true

true

yes
Run Code Online (Sandbox Code Playgroud)

这是预期的行为。a并且b是兄弟姐妹。有三个结果,这有点奇怪,但我认为 Prolog 是绑定A = c, B = dA = d, B = c.

| ?- sibling(a, a).

no
Run Code Online (Sandbox Code Playgroud)

我认为这意味着a …

prolog prolog-dif

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

在列表的开头查找相等元素的数量

给定python中的列表,我想找到列表开头有多少相等的元素.

输入示例:

x1 = ['a','a','b','c','a','a','a','c']
x2 = [1, 1, 1, 3, 1, 1, 1, 8]
x3 = ['foo','bar','foobar']
Run Code Online (Sandbox Code Playgroud)

将输出一些神奇的功能(或一个衬垫):

f(x1) = 2 # There are 2 'a' values in the beginning.
f(x2) = 3 # There are 3 1-values in the beginning.
f(x3) = 1 # Only 1 'foo' in beginning.
Run Code Online (Sandbox Code Playgroud)

如果我做:

sum([1 if x=='a' else 0 for x in x1])
Run Code Online (Sandbox Code Playgroud)

我只是得到x1中'a'的出现次数,而不是一行中前导值的数量.如果有一个不需要知道第一个值的单线程,那将会很高兴.

python indexing list

3
推荐指数
1
解决办法
79
查看次数

为什么用python中的map()函数列表理解可以返回None

>>> counters = [1,2,3,4]
>>> 
>>> [print(i, end=', ') for i in map(inc, counters)]

4, 5, 6, 7, [None, None, None, None]
Run Code Online (Sandbox Code Playgroud)

为什么要打印此代码[None, None, None, None]

python

3
推荐指数
1
解决办法
744
查看次数

防止ipython将输出存储在Out变量中

我目前正在使用熊猫和ipython。由于在执行pandas数据帧操作时会对其进行复制,因此每个单元的内存使用量增加了500 mb。我相信这是因为数据存储在Out变量中,因为默认的python解释器不会发生这种情况。

如何禁用Out变量?

python ipython pandas

3
推荐指数
1
解决办法
268
查看次数

数组中的IndexOf元素

我尝试从元素数组中获取索引.

 var arr = document.getElementsByClassName('class'); //3 elements

 console.log(arr);
 output// [div.class.selected, div.class, div.class, item: function, namedItem: function]

 var selected = document.getElementsByClassName('selected');
 var selected_id = arr.indexOf(selected[0]); 
Run Code Online (Sandbox Code Playgroud)

最后一行代码给出了一个错误Uncaught TypeError: undefined is not a function.我也尝试添加toString()和搜索,但同样的错误.

javascript dom

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

检查字符串是否仅包含某些值,而不包含其他值

print("Hello, welcome to password strength. Test how strong your password is todai!")
password = input("Well enter a password why don't you... ")
print("So your password is", password)
print("Well ok, let's see what i can understand from this...")

if len(password) < 6:   
    print("Your password is too short")    
else:    
    print("Your password is of a good length")    

if password == password.upper():    
    print("Your password has too many uppercase letters")
else:    
    print("Your password has 0 or a couple upper case letters, please consider making your …
Run Code Online (Sandbox Code Playgroud)

python

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