2017-02-27 70 views

回答

0

您可以通過loc使用concat的切片df

np.random.seed(100) 
df1 = pd.DataFrame(np.random.randint(100, size=(5,6)), columns=list('ABCDEF')) 
print (df1) 
    A B C D E F 
0 8 24 67 87 79 48 
1 10 94 52 98 53 66 
2 98 14 34 24 15 60 
3 58 16 9 93 86 2 
4 27 4 31 1 13 83 

df2 = pd.DataFrame({'A':[1,2,3], 
        'B':[4,5,6], 
        'C':[7,8,9], 
        'D':[1,3,5], 
        'E':[5,3,6], 
        'F':[7,4,3]}) 

print (df2) 
    A B C D E F 
0 1 4 7 1 5 7 
1 2 5 8 3 3 4 
2 3 6 9 5 6 3 

#inserted between 4 and 5 index values 
print (pd.concat([df1.loc[:4], df2, df1.loc[4:]], ignore_index=True)) 
    A B C D E F 
0 8 24 67 87 79 48 
1 10 94 52 98 53 66 
2 98 14 34 24 15 60 
3 58 16 9 93 86 2 
4 27 4 31 1 13 83 
5 1 4 7 1 5 7 
6 2 5 8 3 3 4 
7 3 6 9 5 6 3 
8 27 4 31 1 13 83