2-工业大数据分析_实训题及参考答案

更新时间: 试题数量: 购买人数: 提供作者:

有效期: 个月

章节介绍: 共有个章节

收藏
搜索
题库预览
Pandas-时间序列(难度:中) 知识点模块:Pandas-时间序列 任务要求: 某传感器在2024年5月1日至5月7日每小时采集一次温度数据(共168个点)。 1. 使用pd.date_range生成时间索引; 2. 构造DataFrame,包含timestamp和temperature两列; 3. 将timestamp设为索引,按天重采样计算日平均温度; 4. 使用rolling(window=6).mean()计算6小时滑动平均温度; 5. 找出温度最高的时刻和对应的温度值。 评分标准: 代码正确、可运行(60%) 结果符合预期、输出规范(30%) 注释清晰、代码规范(10%) 解题思路 理解题目要求,明确输入输出 按照步骤逐步实现 注意代码规范和注释 实训13: Pandas-时间序列 import pandas as pd import numpy as np # 1. 生成时间索引 timestamps = pd.date_range('2024-05-01', '2024-05-07 23:00', freq='h') # 2. 构造DataFrame np.random.seed(2026) df = pd.DataFrame({ 'timestamp': timestamps, 'temperature': 25 + np.random.normal(0, 3, len(timestamps)) }) # 3. 设为索引,按天重采样 df.set_index('timestamp', inplace=True) daily_avg = df.resample('D')['temperature'].mean() print('日平均温度:') print(daily_avg) # 4. 6小时滑动平均 rolling_avg = df['temperature'].rolling(window=6).mean() print('6小时滑动平均(前5个):') print(rolling_avg.head(10)) # 5. 温度最高的时刻 max_temp_time = df['temperature'].idxmax() print(f'温度最高的时刻: {max_temp_time}, 温度: {df.loc[max_temp_time, "temperature"]:.2f}°C')
Matplotlib-多子图布局(难度:中) 知识点模块:Matplotlib-多子图布局 任务要求: 使用Matplotlib绘制2×2的子图布局,展示某设备一周的监测数据: 1. 子图1:折线图展示7天的温度趋势; 2. 子图2:柱状图展示每天的产量; 3. 子图3:散点图展示温度与产量的关系; 4. 子图4:箱线图展示7天温度的分布统计; 要求:每个子图都有标题,整体添加总标题,使用tight_layout()调整间距。 评分标准: 代码正确、可运行(60%) 结果符合预期、输出规范(30%) 注释清晰、代码规范(10%) 解题思路 理解题目要求,明确输入输出 按照步骤逐步实现 注意代码规范和注释 实训15: Matplotlib-多子图布局 import numpy as np import matplotlib.pyplot as plt np.random.seed(2026) days = np.arange(1, 8) temp = 25 + np.random.normal(0, 2, 7) production = 100 + np.random.randint(-20, 30, 7) fig, axes = plt.subplots(2, 2, figsize=(12, 10)) # 子图1: 折线图 axes[0,0].plot(days, temp, marker='o') axes[0,0].set_title('7天温度趋势') axes[0,0].set_xlabel('天数') axes[0,0].set_ylabel('温度(℃)') axes[0,0].grid(True) # 子图2: 柱状图 axes[0,1].bar(days, production, color='steelblue') axes[0,1].set_title('每天产量') axes[0,1].set_xlabel('天数') axes[0,1].set_ylabel('产量') # 子图3: 散点图 axes[1,0].scatter(temp, production, c='green', s=80) axes[1,0].set_title('温度与产量关系') axes[1,0].set_xlabel('温度') axes[1,0].set_ylabel('产量') # 子图4: 箱线图 axes[1,1].boxplot([temp], tick_labels=['温度']) axes[1,1].set_title('温度分布统计') axes[1,1].set_ylabel('温度(℃)') fig.suptitle('设备一周监测数据', fontsize=16) plt.tight_layout() plt.show() (含图)
1