擅长:python、mysql、java
<p>纯粹在<code>pandas</code>中的一种方法是创建<a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.MultiIndex.from_product.html" rel="nofollow noreferrer">MultiIndex from product</a>,然后将其转换为数据帧:</p>
<pre><code>>>> df1
0
0 drug1
1 drug2
2 drug3
>>> df2
0
0 disease1
1 disease2
2 disease3
df3 = (pd.MultiIndex.from_product([df1[0],df2[0]])
.to_frame()
.reset_index(drop=True))
>>> df3
0 1
0 drug1 disease1
1 drug1 disease2
2 drug1 disease3
3 drug2 disease1
4 drug2 disease2
5 drug2 disease3
6 drug3 disease1
7 drug3 disease2
8 drug3 disease3
</code></pre>