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]
})
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}°")