전세계 식품 생산 총량이 데이터이기 때문에
결과를 안에 있는 데이터로 최대한 가져가고싶었다
그래서 코드를 수정했는데
# 국가별, 연도별 생산량 합계 계산
grouped_data = food_feed_data.groupby(['Area', 'Year', 'Element'])
['Value'].sum().reset_index()
# 연도별 첫 번째와 마지막 값 계산
growth_data = grouped_data.pivot_table(index=['Area', 'Element'], columns='Year', values='Value', aggfunc='sum').reset_index()
# 첫 번째와 마지막 연도 선택 (연도는 데이터에 따라 변경 필요)
first_year = grouped_data['Year'].min()
last_year = grouped_data['Year'].max()
# 성장률 계산 (폭발적 증가를 판단하기 위해 마지막 값 / 첫 번째 값)
growth_data['Growth_Rate'] = (growth_data[last_year] -
growth_data[first_year]) / growth_data[first_year] * 100
# Food와 Feed로 분리해 상위 5개국 추출
top_food_growth = growth_data[growth_data['Element']
== 'Food'].nlargest(5, 'Growth_Rate')
top_feed_growth = growth_data[growth_data['Element'] ==
'Feed'].nlargest(5, 'Growth_Rate')
print("Top 5 Countries with Highest Growth in Food Production:")
print(top_food_growth[['Area', 'Growth_Rate']])
print("\nTop 5 Countries with Highest Growth in Feed Production:")
print(top_feed_growth[['Area', 'Growth_Rate']])
import matplotlib.pyplot as plt
라이브러리를 사용했고
# 상위 5개국 시각화 (Food)
plt.figure(figsize=(10, 6))
plt.bar(top_food_growth['Area'], top_food_growth['Growth_Rate'], color='blue')
plt.title("Top 5 Countries with Highest Growth in Food Production")
plt.ylabel("Growth Rate (%)")
plt.xlabel("Country")
plt.xticks(rotation=45)
plt.show()
# 상위 5개국 시각화 (Feed)
plt.figure(figsize=(10, 6))
plt.bar(top_feed_growth['Area'], top_feed_growth['Growth_Rate'], color='green')
plt.title("Top 5 Countries with Highest Growth in Feed Production")
plt.ylabel("Growth Rate (%)")
plt.xlabel("Country")
plt.xticks(rotation=45)
plt.show()