price我有一个数据框 df,需要创建一个新列,它是with (int 之前计算的)的乘积metric。
price
metric
df['cost'] = df['price'] * metric if (df['status'] == 'online') df['cost'] = 0 if df['status'] == 'offline'
python dataframe pandas
dataframe ×1
pandas ×1
python ×1