如何将元素添加到Pandas序列中?

如何将元素添加到Pandas序列中?

在此程序中,我们将向Pandas序列添加元素。我们将使用append()函数完成此任务。请注意,我们只能将一个序列或系列的列表/元组附加到现有序列中。

算法

步骤1:定义一个Pandas序列s1。
步骤2:定义另一个序列s2。
步骤3:将s2附加到s1。
步骤4:打印最终的附加序列。

示例代码

import pandas as pd

s1 = pd.Series([10,20,30,40,50])
s2 = pd.Series([11,22,33,44,55])

print("S1:\n",s1)
print("\nS2:\n",s2)

appended_series = s1.append(s2)
print("\nFinal Series after appending:\n",appended_series)

输出

S1:
0    10
1    20
2    30
3    40
4    50
dtype: int64

S2:
0    11
1    22
2    33
3    44
4    55
dtype: int64

Final Series after appending:
0    10
1    20
2    30
3    40
4    50
0    11
1    22
2    33
3    44
4    55
dtype: int64

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程