Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python (数据帧)一列替换另一列_Python_Pandas_Dataframe_Replace_Concatenation - Fatal编程技术网

Python (数据帧)一列替换另一列

Python (数据帧)一列替换另一列,python,pandas,dataframe,replace,concatenation,Python,Pandas,Dataframe,Replace,Concatenation,我有两只熊猫数据帧 # python 3 one is | A | B | C | and another is | D | E | F | |---|---|---| |---|---|---| | 1 | 2 | 3 | | 3 | 4 | 6 | | 4 | 5 | 6 | | 8 | 7 | 9 | | ......... |

我有两只熊猫数据帧

# python 3
one is | A | B | C | and another is | D | E | F |
       |---|---|---|                |---|---|---|
       | 1 | 2 | 3 |                | 3 | 4 | 6 |
       | 4 | 5 | 6 |                | 8 | 7 | 9 |
       | ......... |                | ......... |
我想得到“预期的结果”

expected result : 

       | A | D | E | F | C |               
       |---|---|---|---|---|               
       | 1 | 3 | 4 | 6 | 3 |               
       | 4 | 8 | 7 | 9 | 6 |               
       | ................. |
        
df1['B'] convert into df2

       
我已经试过了

pd.concat([df1,df2], axis=1, sort=False)

and drop column df['B']
但它似乎不是很有效。
是否可以使用insert()或其他方法解决此问题?

我认为您的方法很好,您也可以在
concat
之前删除列:

pd.concat([df1.drop('B', axis=1),df2], axis=1, sort=False)
另一种方法是:


为什么你认为它没有效率?我将尝试它作为你的好建议的第一个方法!非常感谢你,我希望你能圆满结束这一年
df1.drop('B', axis=1).join(df2)