<p>您可以使用<a href="https://docs.python.org/3/library/functions.html#zip" rel="nofollow noreferrer">^{<cd1>}</a>将<code>helpful</code>解压缩到单独的列中:</p>
<pre><code>df['helpful_numerator'], df['helpful_denominator'] = zip(*df['helpful'])
</code></pre>
<p><strong>编辑</strong></p>
<p>正如@MaxU在评论中提到的,如果您想从数据框中删除<code>helpful</code>列,请在选择<code>zip</code>中的列时使用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.pop.html" rel="nofollow noreferrer">^{<cd4>}</a>:</p>
^{pr2}$
<p><strong>计时</strong></p>
<p>使用以下设置创建更大的示例数据帧和函数以进行计时:</p>
<pre><code>df = pd.DataFrame({'A': list('abc'), 'B': [[0,1],[2,3],[4,5]]})
df = pd.concat([df]*10**5, ignore_index=True)
def root(df):
df['C'], df['D'] = zip(*df['B'])
return df
def maxu(df):
return df.join(pd.DataFrame(df.pop('B').tolist(), columns=['C', 'D']))
def flyingmeatball(df):
df['C'] = df['B'].apply(lambda x: x[0])
df['D'] = df['B'].apply(lambda x: x[1])
return df
def psidom(df):
df['C'] = df.B.str[0]
df['D'] = df.B.str[1]
return df
</code></pre>
<p>我得到以下时间安排:</p>
<pre><code>%timeit root(df.copy())
10 loops, best of 3: 70.6 ms per loop
%timeit maxu(df.copy())
10 loops, best of 3: 151 ms per loop
%timeit flyingmeatball(df.copy())
1 loop, best of 3: 223 ms per loop
%timeit psidom(df.copy())
1 loop, best of 3: 283 ms per loop
</code></pre>