Python & Pandas:如何进行条件计算

cqc*_*991 3 python pandas

df['direction']是风向的编号,范围为 1-16。我想把它转换成360-degree system. #1方向是90#267.5,它们顺时针运行。

我可以df['degree'] = 90-(df.direction-1)*22.5,但这会产生negative value,你可以看到下面的输出 ![在此处输入图片说明] 1

但我不知道如何使用conditionalhere, for df['degree']<0, then + 360。我怎样才能做到这一点?

Dee*_*ace 6

df['degree'] = df['degree'].apply(lambda x: x + 360 if x < 0 else x)