enter code here我猜你正在使用axis参数寻找pd.concat:
import numpy as np
import pandas as pd
# dfo = pd.read_clipboard()
df1 = pd.DataFrame(np.random.randint(0, 100, size=[10, 2]), columns=['a', 'b'])
df2 = pd.DataFrame(np.random.randint(0, 100, size=[10, 2]), columns=['a', 'b'])
df = pd.concat([df1, df2], axis=0)
print(df)
那会返回
a b
0 24 57
1 89 70
2 78 49
3 33 63
4 27 7
5 56 73
6 30 94
7 85 38
8 44 86
9 83 36
0 40 50
1 16 14
2 2 26
3 48 97
4 80 72
5 69 43
6 13 26
7 50 7
8 84 13
9 34 77
如果要重新索引df,可以在末尾添加reset_index():
df = df.reset_index(drop=True)
print(df)
0 1
0 0 91
1 86 21
2 48 76
3 98 61
4 28 18
5 38 44
6 67 31
7 27 17
8 4 63
9 48 16
10 95 26
11 2 61
12 23 67
13 4 74
14 82 47
15 64 6
16 66 60
17 3 47
18 14 98
19 16 71
如果“彼此背后”是指并排,则只需将axis=0 更改为axis=1。
但是,我不确定您所说的避免 NaN 是什么意思。