data = [342.8, 337.96, 336.68, 337.94, 337.35, 340.4, 342.42, 341.86, 339.4, 341.76, 342.9, 343.63, 338.88, 339.43]
# 风向角度区分
directions = {
"北": [(348.76, 360), (0, 11.25)],
"北东北": [(11.26, 33.75)],
"东北": [(33.76, 56.25)],
"东东北": [(56.26, 78.75)],
"东": [(78.76, 101.25)],
"东东南": [(101.26, 123.75)],
"东南": [(123.76, 146.25)],
"南东南": [(146.26, 168.75)],
"南": [(168.76, 191.25)],
"南西南": [(191.26, 213.75)],
"西南": [(213.76, 236.25)],
"西西南": [(236.26, 258.75)],
"西": [(258.76, 281.25)],
"西西北": [(281.26, 303.75)],
"西北": [(303.76, 326.25)],
"北西北": [(326.26, 348.75)],
}
# 风向分类 统计个数
count_directions = {direction: 0 for direction in directions}
for angle in data:
for direction, bound_list in directions.items():
for i in bound_list:
if i[0] <= angle <= i[1]:
count_directions[direction] += 1
break
else:
continue
break # 跳出第二层循环
print(count_directions)
# 求 value最大值的key
dominant_direction = max(count_directions, key=count_directions.get)
print("主导风向为:", dominant_direction)
标签:direction,Python,bound,directions,风向,pandas
From: https://www.cnblogs.com/jessecheng/p/17700441.html