pandas.Series.append#

Series.append(to_append, ignore_index=False, verify_integrity=False)[源代码]#

串联两个或多个系列。

1.4.0 版后已移除: 使用 concat() 取而代之的是。有关更多详细信息,请参见 不推荐使用DataFrame.append和Series.append

参数
to_append系列或系列列表/数组

要附加到SELF的序列。

ignore_index布尔值,默认为False

如果为True,则生成的轴将标记为0,1,…,n-1。

verify_integrity布尔值,默认为False

如果为True,则在创建具有重复项的索引时引发异常。

退货
系列

串联系列。

参见

concat

连接DataFrame或Series对象的常规函数。

注意事项

迭代地追加到序列中可能比单个串联在计算上更加密集。更好的解决方案是将值追加到列表中,然后一次将该列表与原始系列连接在一起。

示例

>>> s1 = pd.Series([1, 2, 3])
>>> s2 = pd.Series([4, 5, 6])
>>> s3 = pd.Series([4, 5, 6], index=[3, 4, 5])
>>> s1.append(s2)
0    1
1    2
2    3
0    4
1    5
2    6
dtype: int64
>>> s1.append(s3)
0    1
1    2
2    3
3    4
4    5
5    6
dtype: int64

使用 ignore_index 设置为True:

>>> s1.append(s2, ignore_index=True)
0    1
1    2
2    3
3    4
4    5
5    6
dtype: int64

使用 verify_integrity 设置为True:

>>> s1.append(s2, verify_integrity=True)
Traceback (most recent call last):
...
ValueError: Indexes have overlapping values: [0, 1, 2]