diff --git a/1.py b/1.py new file mode 100644 index 0000000000000000000000000000000000000000..162291542ae31e1330bce3e2efc574f47dbcb5f6 --- /dev/null +++ b/1.py @@ -0,0 +1,106 @@ +import pandas as pd +import matplotlib.pyplot as plt +import seaborn as sns + + +# 加载数据集 +file_path = 'C:\Users\A\Desktop\分行业机器人数据.dta' +data = pd.read_stata(file_path) + +# 设置绘图的美观风格 +sns.set_style("whitegrid") + +# 整体趋势 +# 按年汇总安装量和运营库存 +overall_trend = data.groupby('year').agg({'installations': 'sum', 'operationalstock': 'sum'}).reset_index() + +# Plotting the overall trends +plt.figure(figsize=(12, 6)) +plt.plot(overall_trend['year'], overall_trend['installations'], label='Installations', marker='o') +plt.plot(overall_trend['year'], overall_trend['operationalstock'], label='Operational Stock', marker='x') +plt.title('Global Industrial Robots: Overall Trends') +plt.xlabel('Year') +plt.ylabel('Count') +plt.legend() +plt.show() + +overall_trend.tail() # 显示最近几年的趋势以便快速查看 + +# 按国家分布 +country_distribution = data.groupby('Country').agg({'installations': 'sum', 'operationalstock': 'sum'}).reset_index() +country_distribution.sort_values(by='installations', ascending=False, inplace=True) + +# 绘制按国家分布的图 +plt.figure(figsize=(15, 8)) +sns.barplot(x='installations', y='Country', data=country_distribution.head(10)) +plt.title('Top 10 Countries by Industrial Robot Installations') +plt.xlabel('Total Installations') +plt.ylabel('Country') +plt.show() + +# 按行业分布 +industry_distribution = data.groupby('Industry').agg({'installations': 'sum', 'operationalstock': 'sum'}).reset_index() +industry_distribution.sort_values(by='installations', ascending=False, inplace=True) + +# 绘制按行业分布的图 +plt.figure(figsize=(15, 8)) +sns.barplot(x='installations', y='Industry', data=industry_distribution.head(10)) +plt.title('Top 10 Industries by Industrial Robot Installations') +plt.xlabel('Total Installations') +plt.ylabel('Industry') +plt.show() + +(country_distribution.head(10), industry_distribution.head(10)) # 显示安装量前10的国家和行业以便快速查看 + + +# 重点国家:中国、日本、美国 +key_countries = ['China', 'Japan', 'United States'] +key_countries_data = data[data['Country'].isin(key_countries)] + +# 重点国家的趋势分析 +key_countries_trend = key_countries_data.groupby(['year', 'Country']).agg({'installations': 'sum', 'operationalstock': 'sum'}).reset_index() + +# 绘制重点国家趋势图 +plt.figure(figsize=(15, 8)) +sns.lineplot(x='year', y='installations', hue='Country', data=key_countries_trend, marker='o') +plt.title('Trend of Industrial Robot Installations in Key Countries') +plt.xlabel('Year') +plt.ylabel('Installations') +plt.legend(title='Country') +plt.show() + +# 重点行业:汽车和电子/电气 +key_industries = ['Automotive', 'Electrical/electronics'] +key_industries_data = data[data['Industry'].isin(key_industries)] + +# 重点行业的趋势分析 +key_industries_trend = key_industries_data.groupby(['year', 'Industry']).agg({'installations': 'sum', 'operationalstock': 'sum'}).reset_index() + +# 绘制重点行业趋势图 +plt.figure(figsize=(15, 8)) +sns.lineplot(x='year', y='installations', hue='Industry', data=key_industries_trend, marker='o') +plt.title('Trend of Industrial Robot Installations in Key Industries') +plt.xlabel('Year') +plt.ylabel('Installations') +plt.legend(title='Industry') +plt.show() + +(key_countries_trend.head(), key_industries_trend.head()) # 显示每个重点分析的前几行以便快速查看 + +# 从原始数据集重新加载全球安装量数据 +global_data = data.groupby('year')['installations'].sum() + +# 重新计算全球安装量的年增长率 +global_data_growth = global_data.pct_change().dropna() * 100 # 转换为百分比 + +# 重新绘制年增长率图 +plt.figure(figsize=(14, 7)) +plt.plot(global_data_growth.index, global_data_growth, label='Year-Over-Year Growth Rate', marker='o', linestyle='-') +plt.title('Year-Over-Year Growth Rate of Global Industrial Robot Installations') +plt.xlabel('Year') +plt.ylabel('Growth Rate (%)') +plt.legend() +plt.grid(True) +plt.show() + +global_data_growth.describe() # 提供增长率的统计摘要