擅长:python、mysql、java
<p>如前所述,<code>str.split()</code>后跟<code>explode</code>很有帮助。如果您没有使用Pandas 0.25,那么可以在之后使用<code>melt</code>:</p>
<pre><code>(pd.concat( (df.Shape.str.split('\r\n', expand=True),
df[['Color','Price']]),
axis=1)
.melt(id_vars=['Color', 'Price'], value_name='Shape')
.dropna()
)
</code></pre>
<p>输出:</p>
^{pr2}$