我有文件数据.csv,包含一家店铺的客户体验信息和在该店铺的总花费.
Ranking Total Spent
9.5 1245
5 500.58
7.8 1000.69
3 200
6.2 412.45
我想创建一个名为"体验"的新栏目,其价值取决于"排名"栏目.例如:
ranking >= 8 the new column value will be the string "Very satisfied"
ranking >= 6 && ranking < 8 the new column value will be "Satisfied"
ranking >= 5 && ranking < 6 the new column value will be "Neutral"
ranking >= 3 && ranking < 5 the new column value will be "Bad"
ranking >= 0 && ranking < 3 the new column value will be "Horrible"
因此,所需输出为:
Ranking Total Spent Experience
9.5 1245 Very satisfied
5 500.58 Neutral
7.8 1000.69 Satisfied
3 200 Bad
6.2 412.45 Satisfied
我try 了以下代码,但不起作用:
awk -F,'NR==1{$3="Experience";print;next}
$1>=8 {print $0, "Very satisfied";next}
$1>=6 && $1<8 {print $0, "Satisfied";next}
$1>=5 && $1<6 {print $0, "Neutral";next}
$1>=3 && $1<5 {print $0, "Bad";next}
$1>=0 && $1<3 {print $0, "Horrible";next}' data.csv