2023高教社杯全国大学生数学建模竞赛E题代码解析

2023高教社杯全国大学生数学建模竞赛E题 黄河水沙监测数据分析 代码解析

因为一些不可抗力,下面仅展示部分python代码(第一问的部分),其余代码看文末

首先导入包:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.api as sm
import pmdarima as pm
from sklearn.linear_model import LinearRegression
import seaborn as sns

然后需要移除table的数据,因为重复了:

table = pd.read_excel(r"./data/附件1.xlsx")
for i in range(2017, 2017+5):
#     移除table最后一条数据(重复了)
#     print(table.iloc[len(table)-1])
    table.drop((len(table)-1),inplace=True)
    i = str(i)
    temp = pd.read_excel(r"./data/附件1.xlsx",sheet_name = i)
    table = pd.concat([table, temp])
    table = table.reset_index(drop=True)
table

如下为部分数据预处理代码:

# 数据预处理
time_list = []
for i in range(len(table)):
    m, d, h = str(int(table.iloc[i,1])), str(int(table.iloc[i,2])),str(table.iloc[i,3])
    if(int(table.iloc[i,1])<10):
        m = "0" + str(int(table.iloc[i,1]))
    if(int(table.iloc[i,2])<10):
        d = "0" + str(int(table.iloc[i,2])) 
#     print(m,d)
    time = str(int(table.iloc[i,0]))+"-"+ m+"-"+ d +" "+ h
#     print(time)
    time_list.append(time)

temp = pd.DataFrame(time_list, columns=["时刻"])
temp["时刻"]= pd.to_datetime(temp["时刻"])
# temp.to_csv('example3.csv', index=False)
# temp

第一问的可视化图部分代码:

# 创建子图
fig, axes = plt.subplots(nrows=3, ncols=1, figsize=(10, 10))

# 绘制水位数据
axes[0].plot(data.index, data['水位(m)'], label='Water Level', color='blue')
axes[0].set_ylabel('Water Level (m)')
axes[0].set_title('Water Level Over Time')

# 绘制水流量数据
axes[1].plot(data.index, data['流量(m3/s)'], label='Flow Rate', color='green')
axes[1].set_ylabel('Flow Rate (m^3/s)')
axes[1].set_title('Flow Rate Over Time')

# 绘制含沙量数据
axes[2].plot(data.index, data['含沙量(kg/m3) '], label='Sediment Content', color='red')
axes[2].set_xlabel('Time')
axes[2].set_ylabel('Sediment Content')
axes[2].set_title('Sediment Content Over Time')

得到:

有关思路、相关代码、讲解视频、参考文献等相关内容可以点击下方群名片哦!

相关推荐
BY—-组态15 小时前
国内web组态推荐
前端·物联网·数学建模·编辑器·html·工业互联网
liangbm316 小时前
数学建模笔记—— 非线性规划
笔记·python·数学建模·matlab·算法学习·非线性规划·优化问题
梦想科研社18 小时前
【无人机设计与控制】用于四轴飞行器仿真和控制系统设计的参数驱动的 Simulink 模型
开发语言·数学建模·matlab·无人机
nancheng_single1 天前
2024年高教社杯全国大学生数学建模竞赛题目C题农作物的种植策略思路代码分析
人工智能·python·算法·机器学习·数学建模
愿望会实现吧1 天前
| Origin绘图 |瀑布图的绘制(保姆级教程)
数学建模
C灿灿数模1 天前
2024国赛数学建模C题完整论文:农作物的种植策略
数学建模
蟹堡王首席大厨1 天前
2024 年高教社杯全国大学生数学建模竞赛C题—农作物的种植策略(讲解+代码+成品论文助攻,均已更新完毕)
python·数学建模·高教社杯
知新_ROL2 天前
2024全国大学省数学建模竞赛A题-原创参考论文(部分+第一问代码)
数学建模
Azure_loyal2 天前
【全网最全】2024年数学建模国赛A题30页完整建模文档+17页成品论文+保奖matla代码+可视化图表等(后续会更新)
数学建模
小文数模2 天前
2024国赛数学建模B题完整分析参考论文38页(含模型和可运行代码)
python·数学建模·matlab