擅长:python、mysql、java
<p>这里我不能说计算效率,但我更喜欢这里的语法,因为它与我通常用来生成新行的其他apply lambda修改是一致的:</p>
<pre><code>df['uuid'] = df.apply(lambda _: uuid.uuid4(), axis=1)
</code></pre>
<p>您还可以选择一个随机列来删除axis需求(为什么<code>axis=0</code>是默认值,我永远无法理解):</p>
^{pr2}$
<p>从技术上讲,这些方法的缺点是传入了一个实际上没有使用的变量(<code>_</code>)。有能力做类似于<code>lambda: uuid.uuid4()</code>的功能会稍微好一点,但是{<cd4>}不支持没有参数的lambas,这是合理的,因为它的用例将相当有限。在</p>