From d12967392d50c10e93bb3018a2e79b5d4096a168 Mon Sep 17 00:00:00 2001 From: pe4nf27lt <2107895621@qq.com> Date: Wed, 12 Jun 2024 20:23:51 +0800 Subject: [PATCH] ADD file via upload --- test.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test.py diff --git a/test.py b/test.py new file mode 100644 index 0000000..060e987 --- /dev/null +++ b/test.py @@ -0,0 +1,58 @@ +import csv +import re +from collections import Counter + + + +# 正则表达式匹配时间 +time_pattern = re.compile(r'\d{4}-\d{2}') + +# 初始化计数器 +date_counts = Counter() + +# 打开并读取CSV文件 +with open('congtent.csv', mode='r', encoding='utf-8') as file: + csv_reader = csv.reader(file) + # print(csv_reader) + # header = next(csv_reader) # 跳过标题行 + + for row in csv_reader: + # print(row) + time = row[14] + # print("time", time) + # 搜索时间值 + time_match = time_pattern.search(time) + if time_match: + # print(f"Found time: {time_match.group()}") + date = time_match.group() + date_counts[date] += 1 + +# 打印每一天的时间出现次数 +for date, count in date_counts.items(): + print(f"{date}: {count} times") + +# 可视化展示 +dates = list(date_counts.keys()) +counts = list(date_counts.values()) + +print(dates) +print(counts) + +from pyecharts.charts import Bar +from pyecharts import options as opts + + + +# 创建柱状图 +bar = ( + Bar() + .add_xaxis(dates) + .add_yaxis("数量", counts) + .set_series_opts(itemstyle_opts={'color': 'blue'}) + .set_global_opts(title_opts=opts.TitleOpts(title="日期对应数量柱状图")) +) + +# 生成html文件(可选) +bar.render("bar_chart.html") + +