数据可视化

本博客介绍了一种使用Python进行CSV文件数据加载、处理和可视化的技术。通过matplotlib库,将每周的数据汇总并按日期绘制趋势图,展示了数据的时间序列特征。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import csv
import matplotlib.pyplot  as plt
from datetime import datetime
datestring = '159'
def dataload(filename):
    date = []
    # address = []
    count = []
    with open(filename) as f:
        reader = csv.reader(f)
        header_row = next(reader)
        for line in reader:
            if str(line[1]) == datestring:
                date.append(line[0])
                # address.append(line[1])
                count.append(line[2])
    # return date, address, count
    return date, count


filename = r'C:\Users\Linger\Desktop\dataACC3_3.csv'
# date, address, count = dataload(filename)
date, count = dataload(filename)
newdate = []
# newaddress = []
newcount = []
for i in range(int(len(count) / 7)):
    temp1 = []
    temp2 = []
    for j in range(7):
        temp1.append(date[i * 7 + j])
        temp2.append(count[i * 7 + j])
    newdate.append(temp1)
    newcount.append(temp2)
print(int(len(count) / 7))
fig = plt.figure(figsize=(15,2))

for i in range(0, 6):
    plt.subplot(1,6,i+1)
    xs = [datetime.strptime(d, '%Y/%m/%d').date() for d in newdate[i]]
    plt.plot(xs, newcount[i])
    plt.gcf().autofmt_xdate()
    fig.tight_layout()
plt.show()

fig = plt.figure(figsize=(15,2))
for i in range(6, 12):
    plt.subplot(1,6,i-5)
    xs = [datetime.strptime(d, '%Y/%m/%d').date() for d in newdate[i]]
    plt.plot(xs, newcount[i])
    plt.gcf().autofmt_xdate()
    fig.tight_layout()
plt.show()

fig = plt.figure(figsize=(15,2))
for i in range(12, int(len(count) / 7)):
    plt.subplot(1,6,i-11)
    xs = [datetime.strptime(d, '%Y/%m/%d').date() for d in newdate[i]]
    plt.plot(xs, newcount[i])
    plt.gcf().autofmt_xdate()
    fig.tight_layout()
plt.show()

for i in range(int(len(count) / 7)):
    scale = range(7)
    xs = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Weekday']
    plt.xticks(scale, xs)
    plt.plot(newcount[i])
    plt.title('TRADE_ADDRESS:'+datestring)
plt.show()










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值