Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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 - Fatal编程技术网

Python 复制并连接另一个数据帧中每一行的数据帧

Python 复制并连接另一个数据帧中每一行的数据帧,python,pandas,Python,Pandas,我想为不同数据帧中的每一行创建并堆叠一个数据帧 我尝试通过迭代其中一行并复制和堆叠另一行来实现这一点,但这是一个非常缓慢的过程。有没有一种方法可以做到这一点?输入: a = pd.DataFrame({'first':[1,2,3],'second':['one','two','three']}) b = pd.DataFrame({'alice':['yes','no'],'bob':['no','yes']}) 创建虚拟关键点并合并创建笛卡尔积 a.assign(key=1).merge(

我想为不同数据帧中的每一行创建并堆叠一个数据帧

我尝试通过迭代其中一行并复制和堆叠另一行来实现这一点,但这是一个非常缓慢的过程。有没有一种方法可以做到这一点?

输入:

a = pd.DataFrame({'first':[1,2,3],'second':['one','two','three']})
b = pd.DataFrame({'alice':['yes','no'],'bob':['no','yes']})
创建虚拟关键点并合并创建笛卡尔积

a.assign(key=1).merge(b.assign(key=1), on='key').drop('key',axis=1)
输出:

   first second alice  bob
0      1    one   yes   no
1      1    one    no  yes
2      2    two   yes   no
3      2    two    no  yes
4      3  three   yes   no
5      3  three    no  yes