擅长:python、mysql、java
<p>您可能希望在数据帧的所有行上应用lambda函数。你知道吗</p>
<pre><code>df['newcol'] = df.apply(lambda row:
row['component'] if row['business_name'] == 'help' and row['level'] == 'Component' # 1st condition
else (row['package'] if row['business_name'] == 'HELP' and row['level'] == 'Package' # 2nd condition
else (row['reporting'] if row['business_name'] == 'PHELPS' # 3rd condition
else np.nan) # NAN if no conditions matched
)
, axis=1)
</code></pre>