将pandas数组复制一份拼接在原数组末尾
可以使用concat方法来将两个pandas数组拼接在一起,具体操作如下:
import pandas as pd
# 创建原数组
arr = pd.Series([1, 2, 3])
print("原数组:")
print(arr)
# 复制原数组
arr_copy = arr.copy()
# 拼接数组
new_arr = pd.concat([arr, arr_copy])
print("拼接后的数组:")
print(new_arr)
输出结果为:
原数组:
0 1
1 2
2 3
dtype: int64
拼接后的数组:
0 1
1 2
2 3
0 1
1 2
2 3
dtype: int64
可以看到,通过concat方法将原数组和复制的数组拼接在一起,得到了一个新的数组。
原文地址: https://www.cveoy.top/t/topic/bSco 著作权归作者所有。请勿转载和采集!