python数据分析实验报告_使⽤Python3进⾏⽓象数据分析项⽬简介 :本实验将对意⼤利北部沿海地区的⽓象数据进⾏分析与可视化。我们在实验过程中先会运⽤ Python 中 matplotlib 库的对数据进⾏图表化处理,最终在图表分析的⽀持下得出我们的结论。
解决“海洋对⼀个地区的⽓候有何影响”的问题。
待检验的假设 :靠海对⽓候的影响。
选作样本的城市列表如下:
Ferrara(费拉拉)
Torino(都灵)
Mantova(曼托⽡)
Milano(⽶兰)
Ravenna(拉⽂纳)
Asti(阿斯蒂)
Bologna(博洛尼亚)
Piacenza(⽪亚琴察)
Cesena(切塞纳)
Faenza(法恩莎)
查看10个城市的天⽓数据⽂件:
!apt-get install tree
!tree WeatherData/
导⼊所需的包:
import numpy as np
import pandas as pd
import datetime
读取数据:
df_ferrara = pd.read_csv('WeatherData/ferrara_270615.csv')
df_milano = pd.read_csv('WeatherData/milano_270615.csv')
df_mantova = pd.read_csv('WeatherData/mantova_270615.csv')
df_ravenna = pd.read_csv('WeatherData/ravenna_270615.csv')
df_torino = pd.read_csv('WeatherData/torino_270615.csv')
df_asti = pd.read_csv('WeatherData/asti_270615.csv')
df_bologna = pd.read_csv('WeatherData/bologna_270615.csv')
df_piacenza = pd.read_csv('WeatherData/piacenza_270615.csv')
df_cesena = pd.read_csv('WeatherData/cesena_270615.csv')
df_faenza = pd.read_csv('WeatherData/faenza_270615.csv')
导⼊必要的库:
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from dateutil import parser
**温度数据分析 **
分析⼏个不同城市的⽓温趋势:
# 读取温度和⽇期数据
y1 = df_ravenna['temp']
x1 = df_ravenna['day']
y2 = df_faenza['temp']
x2 = df_faenza['day']
y3 = df_cesena['temp']
x3 = df_cesena['day']
y4 = df_milano['temp']
x4 = df_milano['day']
y5 = df_asti['temp']
古戈尔x5 = df_asti['day']
y6 = df_torino['temp']
x6 = df_torino['day']
# 把⽇期从 string 类型转化为标准的 datetime 类型
day_ravenna = [parser.parse(x) for x in x1]
day_faenza = [parser.parse(x) for x in x2]
day_cesena = [parser.parse(x) for x in x3]
day_milano = [parser.parse(x) for x in x4]
day_asti = [parser.parse(x) for x in x5]
day_torino = [parser.parse(x) for x in x6]
# 调⽤ subplots() 函数,重新定义 fig, ax 变量
fig, ax = plt.subplots()
hours = mdates.DateFormatter('%H:%M')
ax.xaxis.set_major_formatter(hours)
#这⾥需要画出三根线,所以需要三组参数, 'g'代表'green'
ax.plot(day_ravenna,y1,'r',day_faenza,y2,'r',day_cesena,y3,'r')dnf魔神刷图加点
茶叶的基本知识ax.plot(day_milano,y4,'g',day_asti,y5,'g',day_torino,y6,'g')
执⾏上述代码⽣成如图所⽰的图表。离海最近的三个城市的⽓温曲线使⽤红⾊,⽽离海最远的三个城市的曲线使⽤绿⾊。离海最近的三个城市的最⾼⽓温⽐离海最远的三个城市的最⾼⽓温低很多,⽽最低⽓温差别较⼩。
⽤线性图表⽰⽓温最值点和离海远近之间的关系:
# dist 是⼀个装城市距离海边距离的列表
dist = [df_ravenna['dist'][0],
df_cesena['dist'][0],
df_faenza['dist'][0],
df_ferrara['dist'][0],
df_bologna['dist'][0],
df_mantova['dist'][0],
df_piacenza['dist'][0],
df_milano['dist'][0],
df_asti['dist'][0],
df_torino['dist'][0]
]
# temp_max 是⼀个存放每个城市最⾼温度的列表
temp_max = [df_ravenna['temp'].max(),
df_cesena['temp'].max(),
df_faenza['temp'].max(),
df_ferrara['temp'].max(),
df_bologna['temp'].max(),
df_mantova['temp'].max(),
df_piacenza['temp'].max(),
df_milano['temp'].max(),
df_asti['temp'].max(),
df_torino['temp'].max()
]
# temp_min 是⼀个存放每个城市最低温度的列表
temp_min = [df_ravenna['temp'].min(),
df_cesena['temp'].min(),
df_faenza['temp'].min(),
df_ferrara['temp'].min(),
df_bologna['temp'].min(),
df_mantova['temp'].min(),
df_piacenza['temp'].min(),
df_milano['temp'].min(),
df_asti['temp'].min(),
df_torino['temp'].min()
感悟深秋的唯美句子]
画出最⾼温:
fig, ax = plt.subplots()
ax.plot(dist,temp_max,'ro')
执⾏代码后结果如图所⽰。海洋的影响衰减得很快,离海 60~70 公⾥开外,⽓温就已攀升到⾼位。
分析最低温度:
# axis 函数规定了 x 轴和 y 轴的取值范围
plt.axis((0,400,15,25))
我是歌手第二季冠军
plt.plot(dist,temp_min,'bo')
执⾏代码如图所⽰。由此可得,最低⽓温⼏乎与离海远近⽆关。
湿度数据分析
分析近海城市和内陆城市的湿度趋势
# 读取湿度数据
y1 = df_ravenna['humidity']
x1 = df_ravenna['day']
y2 = df_faenza['humidity']
x2 = df_faenza['day']
y3 = df_cesena['humidity']
x3 = df_cesena['day']
y4 = df_milano['humidity']
x4 = df_milano['day']
y5 = df_asti['humidity']
x5 = df_asti['day']
y6 = df_torino['humidity']
x6 = df_torino['day']
# 重新定义 fig 和 ax 变量
fig, ax = plt.subplots()郭敬明有多高
# 把时间从 string 类型转化为标准的 datetime 类型
day_ravenna = [parser.parse(x) for x in x1]
day_faenza = [parser.parse(x) for x in x2]
day_cesena = [parser.parse(x) for x in x3]
day_milano = [parser.parse(x) for x in x4]
day_asti = [parser.parse(x) for x in x5]
day_torino = [parser.parse(x) for x in x6]
# 规定时间的表⽰⽅式
hours = mdates.DateFormatter('%H:%M')
ax.xaxis.set_major_formatter(hours)
#表⽰在图上
ax.plot(day_ravenna,y1,'r',day_faenza,y2,'r',day_cesena,y3,'r')
ax.plot(day_milano,y4,'g',day_asti,y5,'g',day_torino,y6,'g')
执⾏上述代码后结果如图所⽰。近海城市的湿度要⼤于内陆城市,全天湿度差距在 20% 左右。
发布评论