编辑代码

# coding:utf-8
#JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
import numpy as np
import pandas as pd

# 示例数据框
data = pd.DataFrame({
    'Year': [2020, 2021, 2022],
    'Agriculture': [24.5, 23.1, 22.0],
    'Industry': [8.7, 9.2, 10.0],
    'Services': [66.8, 67.7, 68.0]
})

# 计算Moore值
def moore_angle(row1, row2):
    vec1 = row1[['Agriculture', 'Industry', 'Services']].values
    vec2 = row2[['Agriculture', 'Industry', 'Services']].values
    dot_product = np.dot(vec1, vec2)
    norm1 = np.linalg.norm(vec1)
    norm2 = np.linalg.norm(vec2)
    return np.degrees(np.arccos(dot_product / (norm1 * norm2)))

# 输出结果
for i in range(1, len(data)):
    theta = moore_angle(data.iloc[i-1], data.iloc[i])
    print(f"{data.iloc[i-1]['Year']}-{data.iloc[i]['Year']} Moore值: {theta:.2f}°")