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/ngOd 著作权归作者所有。请勿转载和采集!