编写一个 Python 代码,将两个 Pandas 系列连接成一个系列,而不重复索引
pythonpandasserver side programmingprogramming更新于 2024/6/19 5:32:17
输入 − 假设您有一个系列,连接值而不重复索引的结果是,
0 1 1 2 2 3 3 4 4 5 5 6
解决方案
为了解决这个问题,我们将遵循这两个步骤 −
定义两个系列
连接两个系列并将 ignore_index 值应用为 True 以查找结果。它的定义如下,
pd.concat([series_one,series_two],ignore_index=True)
示例
让我们看看完整的实现,以便更好地理解 −
import pandas as pd series_one = pd.Series([1,2,3]) series_two = pd.Series([4,5,6]) print(pd.concat([series_one,series_two],ignore_index=True))
输出
0 1 1 2 2 3 3 4 4 5 5 6
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/
打印
下一节:用 Python 编写一个程序,打印给定日期系列中的一年中的某一天 ❯❮ 上一节:编写 Python 代码创建一个具有范围值的系列,生成一个新行作为所有值的总和,然后将该系列转换为 json 文件

