标签: append

l.append [i],对象不可订阅?

当我做:

l = []
for i in range(10):
    if i%3 == 0 or i%5 == 0:
        l.append[i]
print sum(l)
Run Code Online (Sandbox Code Playgroud)

我明白了

Traceback (most recent call last):
  File "PE1.py", line 4, in <module>
    l.append[i]
TypeError: 'builtin_function_or_method' object is not subscriptable
Run Code Online (Sandbox Code Playgroud)

真的没有办法追加通过条件的所有i吗?

python for-loop list append

5
推荐指数
2
解决办法
9840
查看次数

按放置金额附加订购商品

我正在使用此功能按金额按顺序添加新项目.此功能每30-50ms调用一次.

var insertBefore = false;
container.find('.roll-user-row[data-user-id="' + user_data.id + '"]').remove();

container.children().each(function () {
    var betContainer = $(this), itemAmount = $(this).attr('data-amount'), betId = $(this).attr('data-user-id');
    if (itemAmount < betData.totalAmount) {
        insertBefore = betContainer;
        return false;
    }
});

if (insertBefore) {
    $(template).insertBefore(container);
} else {
    container.prepend(template);
}
Run Code Online (Sandbox Code Playgroud)

itemAmount = $(this).attr('data-amount')是整数,betData.totalAmount也是整数.如果附加速度低于±300毫秒 - 一切都运行良好.如果快速追加我得到这个结果:

随机顺序

这甚至没有关闭我想要的 - 那是随机的.怎么解决这个?

javascript jquery insert append

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

如何使用elasticsearch python追加现有字段?

我正在使用 kibana 和 Elasticsearch 版本 5.1.1 和 python 版本 3.6。

我已经像这样创建了索引 put_books

添加用户的功能是这样的:

def add_user(first_name, last_name, age, mail):
    doc = {"first_name": "" + first_name, "last_name": "" + last_name, "age": age, "email": "" + mail}
    global id_user
    res = es.index(index="books", doc_type="user", id=id_user, body=doc)
    id_user += 1
    print(res['result']) 
Run Code Online (Sandbox Code Playgroud)

并添加首选项:

def add_preferences(preferences, i):
    doc = es.get(index="books", doc_type="user", id=id_book)
    res = es.update(index="books", doc_type="user", id=i, body={'doc':{"keyword_preferences": preferences}})
Run Code Online (Sandbox Code Playgroud)

我的问题是:当我想添加首选项时,它会成功,但如果我想再次添加首选项,它会替换它:

id_user = 1
nom = "nom_1"
prenom = "prenom_1"
age = 45
email = "adresse_mail_1" …
Run Code Online (Sandbox Code Playgroud)

field append python-3.x elasticsearch-5 kibana-5

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

Pandas python 合并多个文件文本

我有 2 个文件文本:file1.txt

abc
fdg
erg
Run Code Online (Sandbox Code Playgroud)

文件2.txt

pot
ezr
fds
Run Code Online (Sandbox Code Playgroud)

我制作了一个包含 2 列的 csv 文件

columns = ['first','second']
my_df  = pd.DataFrame(columns = columns)
Run Code Online (Sandbox Code Playgroud)

我不知道如何在列上添加文件 txt

我想

   first   second
0   abc     pot
1   fdg     ezr
2   erg     fds
Run Code Online (Sandbox Code Playgroud)

我尝试使用 loc 或追加,但结果很糟糕。我不知道如何将文件文本中的项目放在 df 上的好位置。你能帮助我吗 ?

append python-3.x pandas

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

Python Pandas:仅当列值唯一时才将数据帧附加到另一个数据帧

我有两个数据框想要附加在一起。以下是示例。

df_1:

Code    Title
103     general checks 
107     limits
421     horseshoe
319     scheduled 
501     zonal 
Run Code Online (Sandbox Code Playgroud)

df_2

Code    Title
103     hello 
108     lucky eight 
421     little toe 
319     scheduled cat
503     new item 
Run Code Online (Sandbox Code Playgroud)

仅当 df_2 中的代码号在 df_1 中不存在时,我才想将 df_2 附加到 df_1。

下面是我想要的数据框:

Code    Title
103     general checks 
107     limits
421     horseshoe
319     scheduled 
501     zonal 
108     lucky eight 
503     new item
Run Code Online (Sandbox Code Playgroud)

我已经通过 Google 和 Stackoverflow 进行了搜索,但找不到有关此特定案例的任何内容。

python append conditional-statements pandas

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

有条件地将属性附加到 Laravel 中的模型

每当调用模型范围时是否可以将属性附加到我的模型?

例如,在我的控制器中,我想调用一个作用域来附加这些动态属性,例如:

$Media_query = OutDoorMedia::query();
$Media_query->orderby('created_at', 'desc');
$Media_query->PreviouslyOrdered();
$Media = $Media_query->get();
Run Code Online (Sandbox Code Playgroud)

在我的模型中我想做类似的事情:

class OutDoorMedia extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'id',
        'user_id',
        'address',
        'location',
        'media_type',
    ];
}

class scopePreviouslyOrdered extends OutDoorMedia
{
public $appends = ['previously_ordered'];

public function getPreviouslyOrderedAttribute()
{
    if ($this->hasMany('App\Models\OutDoorMediaOrders', 'odm_id', 'id')->Where(function ($query) {
        $query->where('status', MEDIA_ORDER_CHECKOUT_STATUS)
            ->orWhere('status', STATUS_TO_PAY);
    })->exists()) {
        return true;
    } else {
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

}

但它不起作用,我知道这是错误的,如何实现这一目标?

php orm append laravel eloquent

5
推荐指数
2
解决办法
2万
查看次数

Kotlin附加到文件

我对Kotlin绝对陌生,似乎我无法获取追加文件过程。我有val路径给定的文件名:String =“ ..... txt”我想在我的类中使用以下方法:line:String并将其附加在文件的末尾(在新行上)。我的测试用例是:用两个不同的行对方法进行两次结果调用,例如“ foo”和“ bar”,我希望文件如下:

foo
bar
Run Code Online (Sandbox Code Playgroud)

如果我的方法如下所示,它将起作用:

fun writeLine(line: String) {
    val f = File(path!!)
    f.appendText(line + System.getProperty("line.separator"))
}
Run Code Online (Sandbox Code Playgroud)

而且它绝对不会以这种方式工作:

    fun writeLine(line: String) {
        val f = File(path!!)
        f.bufferedWriter().use { out->
        out.append(line)
        out.newLine()
        }
    }
Run Code Online (Sandbox Code Playgroud)

每次调用时都会重写我的文件,因此我的文件中只有“ bar”。它也不能与printWriter一起使用:

    fun writeLine(line: String) {
        val f = File(path!!)
        f.printWriter().use { out->
        out.append(line)
        }
    }
Run Code Online (Sandbox Code Playgroud)

我得到的结果与BufferedWriter相同。为什么?我就是听不懂。如何附加BufferedWriter或PrintWriter?

io append kotlin

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

将元素添加到 R 中向量的开头

我有这个 for 循环,它调用产生数字向量的函数

例如,向量将导致:

[1] 42 42 6 693 6222
Run Code Online (Sandbox Code Playgroud)

从上面的 for 循环。

我想将“x”添加到每个向量的开头。看来去的效率不高

append("x", vec1)
# This is an example of what I want produced:
[1] x 42 42 6 693 6222
Run Code Online (Sandbox Code Playgroud)

多次。有没有办法将“x”添加为 for 循环内的第一个元素?谢谢。

for-loop r list vector append

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

PrimeNG p 表分页下拉列表在全屏模式下隐藏

代码如下:

<p-table
    [columns]="colsHistoryLogEntryList"
    [value]="entity.historyLogEntryList"
    [resizableColumns]="true"
    [autoLayout]="true"
    [paginator]="true"
    [rows]="5"
    [rowsPerPageOptions]="[5, 10, 25, 50, 100]"
    paginatorDropdownAppendTo="body"
    class="ui-table-historyEntry-list"
    [rowHover]="true"
>
Run Code Online (Sandbox Code Playgroud)

当页面最大化时,下拉列表呈现到底部并且部分隐藏。但是当页面缩小时,它会正确地呈现为向上方向。

如何强制下拉列表始终可见?

单击以显示屏幕截图

pagination append primeng p-table

5
推荐指数
0
解决办法
1762
查看次数

将第一行按组附加到原始数据

我有带有分组变量“ID”和一些值的数据:

ID, Value
1, 1
1, 2
1, 3
1, 4
2, 5
2, 6 
2, 7
2, 8
Run Code Online (Sandbox Code Playgroud)

在每个组中,我想在最后一行之后附加第一行。期望的结果:

ID, Value
1, 1
1, 2
1, 3
1, 4
1, 1 # First row of ID 1 inserted as last row in the group
2, 5
2, 6 
2, 7
2, 8
2, 5 # First row of ID 2 inserted as last row in the group
Run Code Online (Sandbox Code Playgroud)

我有 5000 行这个。

r append data-manipulation

5
推荐指数
2
解决办法
204
查看次数