我试图根据不同列中的值向数据框添加注释。这是我的工厂销售数据:
UPC Quantity Name Size Color Type
0 11313 68 Crocus small purple perennial
1 42164 51 Sunflower large yellow annual
2 53890 76 Zinnia small pink annual
3 54885 85 Daisy medium white perennial
4 77314 80 Rose large red perennial
5 79375 62 Mum medium yellow annual
6 94281 1 Dahlia large orange perennial
7 95085 41 Marigold small orange annual
import pandas as pd
df = pd.read_csv("Plants_in_stock.csv")
#I add a column to annotate a discount for products I want to move
df['Discount'] = ''
df
This is what the output looks like so far
现在,如果“数量”> 80,我想在“折扣”列中添加25%,如果“类型” ==“年度”,则添加50%。
我应该如何进行?
答案 0 :(得分:2)
使用function number_game(x, y) {
let result = [];
let min=0, max=0;
if(x==y) {
return result;
} else if (x > y) {
min = y;
max = x;
} else {
min = x;
max = y;
}
for (let i = min; i <= max; i++){
if (i%2===0 && x > y && i!=min && i!=max) {
result.push(i);
}
if (i%2===1 && x < y && i!=min && i!=max) {
result.push(i);
}
}
return result;
}
console.log(number_game(12,0));
console.log(number_game(2,12));
console.log(number_game(0,0));
console.log(number_game(13,1));
console.log(number_game(3,13));
console.log(number_game(1,1));
console.log(number_game(1,1000));
console.log(number_game(3,1300));
:
np.select