如果我理解正确,那么您需要以下内容:In [36]:
df = pd.DataFrame({'direction':np.random.randint(1,17,20)})
df
Out[36]:
direction
0 13
1 12
2 4
3 5
4 16
5 6
6 3
7 16
8 12
9 2
10 14
11 13
12 8
13 9
14 8
15 12
16 9
17 2
18 7
19 8
In [37]:
df['degrees'] = (90 - (df['direction'] -1) * 22.5)
df.loc[df['degrees']<0,'degrees'] += 360.0
df
Out[37]:
direction degrees
0 13 180.0
1 12 202.5
2 4 22.5
3 5 0.0
4 16 112.5
5 6 337.5
6 3 45.0
7 16 112.5
8 12 202.5
9 2 67.5
10 14 157.5
11 13 180.0
12 8 292.5
13 9 270.0
14 8 292.5
15 12 202.5
16 9 270.0
17 2 67.5
18 7 315.0
19 8 292.5