<p>使用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.pop.html" rel="nofollow noreferrer">^{<cd1>}</a>+<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.split.html" rel="nofollow noreferrer">^{<cd2>}</a>+<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.stack.html" rel="nofollow noreferrer">^{<cd3>}</a>+<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.rename.html" rel="nofollow noreferrer">^{<cd4>}</a>+<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html" rel="nofollow noreferrer">^{<cd5>}</a>表示新<code>Series</code>,然后<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.join.html" rel="nofollow noreferrer">^{<cd7>}</a>表示原始:</p>
<hr/>
<pre><code>tmdb_data = pd.DataFrame({'movie':['Jursassic World', 'Insurgent'],
'cast':['Chris Patt|Bryce Dallas Howard|Irrfan Khan',
'Shailene Woodley|Theo James']},
columns=['movie', 'cast'])
print (tmdb_data)
movie cast
0 Jursassic World Chris Patt|Bryce Dallas Howard|Irrfan Khan
1 Insurgent Shailene Woodley|Theo James
df1 = (tmdb_data.join(tmdb_data.pop('cast').str.split('|', expand=True)
.stack()
.reset_index(level=1, drop=True)
.rename('cast'))
.reset_index(drop=True))
print (df1)
movie cast
0 Jursassic World Chris Patt
1 Jursassic World Bryce Dallas Howard
2 Jursassic World Irrfan Khan
3 Insurgent Shailene Woodley
4 Insurgent Theo James
</code></pre>