Python项目:数据可视化_下载数据【笔记】

源自《Python编程:从入门到实践》

作者: Eric Matthes

02 下载数据

2.1 sitka_weather_07-2021_simple.csv

from pathlib import Path
import matplotlib.pyplot as plt
import csv
from datetime import datetime

path = Path('D:\CH16\sitka_weather_07-2021_simple.csv')
lines = path.read_text().splitlines()

reader = csv.reader(lines)
header_row = next(reader)
print(header_row)

#提取最高温度
#提取日期

highs = []
dates = []

for row in reader:
    high = int(row[4])
    highs.append(high)
    current_date = datetime.strptime(row[2], '%Y-%m-%d')
    dates.append(current_date)
print(highs)
print(dates)

#绘制温度图
plt.style.use('seaborn-v0_8')
fig, ax = plt.subplots()
ax.plot(dates, highs, color='red')

ax.set_title('Daily High Temperatures,July 2021', fontsize=24)
ax.set_xlabel('Date', fontsize=14)
ax.set_ylabel('Temperature(F)', fontsize=14)

plt.show()

2.2 sitka_weather_2021_simple.csv

from pathlib import Path
import matplotlib.pyplot as plt
import csv
from datetime import datetime

path = Path('D:\CH16\sitka_weather_2021_simple.csv')
lines = path.read_text().splitlines()

reader = csv.reader(lines)
header_row = next(reader)
print(header_row)

#提取最高温度
#提取日期

highs = []
dates = []

for row in reader:
    high = int(row[4])
    highs.append(high)
    current_date = datetime.strptime(row[2], '%Y-%m-%d')
    dates.append(current_date)
print(highs)
print(dates)

#绘制温度图
plt.style.use('seaborn-v0_8')
fig, ax = plt.subplots()
ax.plot(dates, highs, color='red')

ax.set_title('Daily High Temperatures,2021', fontsize=24)
ax.set_xlabel('', fontsize=14)
ax.set_ylabel('Temperature(F)', fontsize=14)

plt.show()

相关推荐

  1. Python 数据

    2024-05-25 21:24:29       54 阅读
  2. Python机器学习项目开发实战:数据

    2024-05-25 21:24:29       35 阅读
  3. Python数据分析与笔记 十 关联

    2024-05-25 21:24:29       31 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-25 21:24:29       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-25 21:24:29       101 阅读
  3. 在Django里面运行非项目文件

    2024-05-25 21:24:29       82 阅读
  4. Python语言-面向对象

    2024-05-25 21:24:29       91 阅读

热门阅读

  1. 基于Python的招聘岗位数据分析系统的设计与实现

    2024-05-25 21:24:29       37 阅读
  2. 1.4 接入网和物理媒体

    2024-05-25 21:24:29       30 阅读
  3. Mysql 的 binlog 有几种格式?

    2024-05-25 21:24:29       31 阅读
  4. tp5问题集记录 一

    2024-05-25 21:24:29       36 阅读
  5. flask中的路由是什么意思

    2024-05-25 21:24:29       28 阅读
  6. 查询MongoDB中某个数据库的占用空间大小

    2024-05-25 21:24:29       33 阅读
  7. 信息安全法律法规复习

    2024-05-25 21:24:29       34 阅读