# 如何加入来自同一数据框中2列，但是从第2列取列A至d从列1和M为P？

##### 问题描述投票：1回答：2

``````Index   Col_A   Col_B   Col_C
0   1   2   1
1   1   3   1
2   1   6   1
3   1   3   1
4   1   9   1
5   1   3   1
6   1   2   2
7   1   4   4
8   1   6   6
9   1   7   7
10  1   1   1
``````

``````df['Col_A'] = pd.concat(df['Col_A'].iloc[0:5], df['Col_B'].iloc[5:10])
``````

python pandas dataframe
##### 2个回答
0

``````    Col_A  Col_B  Col_C
0       1      2      3
1       1      2      3
2       1      2      3
3       1      2      3
4       1      2      3
5       1      2      3
6       1      2      3
7       1      2      3
8       1      2      3
9       1      2      3
10      1      2      3
``````

``````df['Col_C'] = pd.concat((df['Col_A'].iloc[:6], df['Col_B'].iloc[6:]))
``````

``````    Col_A  Col_B  Col_C
0       1      2      1
1       1      2      1
2       1      2      1
3       1      2      1
4       1      2      1
5       1      2      1
6       1      2      2
7       1      2      2
8       1      2      2
9       1      2      2
10      1      2      2
``````

0

``````df = pd.DataFrame({'a':[1]*11, 'b':[2,3,6,3,9,3,2,4,6,7,1]})

x = list(df.loc[:5,'a']) #  + df.iloc[6:,'b']
x.extend(list(df.loc[6:,'b']))
df['c'] = x
print(df)
``````

``np.where``