diff --git a/Weather_Visual/PlotShow.py b/Weather_Visual/PlotShow.py new file mode 100644 index 0000000..e2b6c94 --- /dev/null +++ b/Weather_Visual/PlotShow.py @@ -0,0 +1,50 @@ +# -*- coding: gbk -*- +import csv +from matplotlib import pyplot as plt, ticker +from datetime import datetime + +from matplotlib.ticker import MultipleLocator + +filename = 'changsha天气.csv' + +with open(filename) as f: + reader = csv.reader(f) + header_row = next(reader) + + #获取每天的最高气温数据 + dates: [datetime] = [] + higts, lows = [], [] + for row in reader: + try: + current_date = datetime.strptime(row[0], '%Y-%m-%d') + higt = int(row[1]) + low = int(row[2]) + except ValueError: + print(current_date, '缺少信息') + else: + dates.append(current_date) + higts.append(higt) + lows.append(low) + +#根据数据绘制图形,设置窗口大小 +fig = plt.figure(dpi=150, figsize=(12, 8)) +#plot 拆线图 alpha=(0.1 - 0.9)表示透明度,0为全透明,1为不透明 +plt.plot(dates, higts, c='red', alpha=0.5) +plt.plot(dates, lows, c='blue', alpha=0.5) +#填充区间 +plt.fill_between(dates, lows, higts, facecolor='black', alpha=0.1) +#设置图形格式 +plt.rcParams['font.sans-serif'] = ['SimHei'] +plt.title('长沙2023全年气温折线图', fontsize=20, weight='bold', color='blue', fontstyle='italic', loc='center') +plt.xlabel('', fontsize=16) +#日期标签倾斜 +fig.autofmt_xdate() +plt.ylabel("温度", fontsize=16, loc='top') +plt.xlabel("年-月", fontsize=16, loc='right') +#设置刻度标记的大小 +plt.tick_params(axis='both', which='major',direction='in', pad=3,labelsize=16) + + +plt.savefig('长沙2023年气温折线图.png') +plt.show() + diff --git a/Weather_Visual/SpriderWindow.py b/Weather_Visual/SpriderWindow.py new file mode 100644 index 0000000..f3f859f --- /dev/null +++ b/Weather_Visual/SpriderWindow.py @@ -0,0 +1,106 @@ +import os +import tkinter as tk +from tkinter import simpledialog +from ttkbootstrap import Style +import requests +from lxml import etree +import csv + + +# 淇濇寔鍘熸湁get_data鍑芥暟涓嶅彉 +def get_data(city, year_month): + url = f"https://lishi.tianqi.com/{city}/{year_month}.html" + weather_info = [] + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0" + } + try: + response = requests.get(url, headers=headers) + response.raise_for_status() # 妫鏌ヨ姹傛槸鍚︽垚鍔 + html = etree.HTML(response.text) + thrui_list = html.xpath("//ul[@class='thrui']/li") + for li in thrui_list: + day_weather_info = {} + day_weather_info['day_time'] = li.xpath("./div[1]/text()")[0].split(" ")[0] + high = li.xpath("./div[2]/text()")[0].split(" ")[0] + day_weather_info['high'] = high[:high.find('C')] + low = li.xpath("./div[3]/text()")[0].split(" ")[0] + day_weather_info['low'] = low[:low.find('C')] + day_weather_info['weather'] = li.xpath("./div[4]/text()")[0] + day_weather_info['wind'] = li.xpath("./div[5]/text()")[0] + weather_info.append(day_weather_info) + except requests.RequestException as e: + print(f"璇锋眰閿欒锛歿e}") + return weather_info + + +# 娣诲姞涓涓畝鍗曠殑鍩庡競涓枃鍒拌嫳鏂囨槧灏勮〃 +city_to_english = { + "闀挎矙": "changsha", + "鏍床": "zhuzhou", + "婀樻江": "xiangtan", + "琛¢槼": "hengyang", + "閭甸槼": "shaoyang", + "宀抽槼": "yueyang", + "甯稿痉": "changde", + "寮犲鐣": "zhangjiajie", + "鐩婇槼": "yiyang", + "閮村窞": "chenzhou", + "姘稿窞": "yongzhou", + "鎬鍖": "huaihua", + "濞勫簳": "loudi", + + # 娣诲姞鏇村鍩庡競... +} + + +def on_submit(city_entry): + city = city_entry.get() + if city in city_to_english: + city = city_to_english[city] + else: + result_label.config(text=f"鏈壘鍒板煄甯 {city} 瀵瑰簲鐨勮嫳鏂囨槧灏勶紝璇疯緭鍏ユ纭殑鍩庡競鍚") + return + + weathers = [] + + for month in range(1, 13): + weather_time = "2023" + ('0' + str(month) if month < 10 else str(month)) + weather = get_data(city, weather_time) + weathers.extend(weather) + + with open(f'{city}澶╂皵.csv', 'w', newline='') as csvfile: + writer = csv.writer(csvfile) + writer.writerow(["鏃ユ湡", "鏈楂樻皵娓", "鏈浣庢皵娓", "澶╂皵", "椋庡悜/椋庨"]) + for day_weather in weathers: + writer.writerow(list(day_weather.values())) + result_label.config(text=f"{city}鐨勫ぉ姘旀暟鎹凡鎴愬姛淇濆瓨鑷'{city}澶╂皵.csv'") + + +def main(): + global result_label + + root = tk.Tk() + + # # 缃《鏍 + # music_path = os.path.join(os.path.abspath("__try__"), "瀹夋渤妗.mp3") + # play_music(music_path) + + root.title("澶╂皵鏁版嵁鐖彇宸ュ叿") + root.geometry("600x400+100+100") + tk.Label(root, text="璇疯緭鍏ュ煄甯傚悕:", font=("Arial", 14, "bold"), pady=10).pack() + city_entry = tk.Entry(root, font=("Arial", 14, "bold"), relief="flat") + city_entry.pack() + style = Style() + style = Style(theme='yeti') + submit_button = tk.Button(root, text="鎻愪氦", width=8, command=lambda: on_submit(city_entry)) + submit_button.pack() + + result_label = tk.Label(root, text="") + result_label.pack() + + root.mainloop() + + +if __name__ == "__main__": + main() diff --git a/Weather_Visual/WeatherShow.py b/Weather_Visual/WeatherShow.py new file mode 100644 index 0000000..b5b6738 --- /dev/null +++ b/Weather_Visual/WeatherShow.py @@ -0,0 +1,45 @@ +import pandas as pd +from pyecharts import options as opts +from pyecharts.charts import Pie, Bar, Timeline + +js = pd.read_csv('changsha澶╂皵.csv', encoding='gbk') + +js['鏃ユ湡'] = js['鏃ユ湡'].apply(lambda x: pd.to_datetime(x)) + +js['month'] = js['鏃ユ湡'].dt.month +js_agg1 = js.groupby(['month', '澶╂皵']).size().reset_index() + +js_agg1.columns = ['month', 'tianqi', 'count'] + +print(js_agg1[js_agg1['month'] == 1][['tianqi', 'count']] \ + .sort_values(by='count', ascending=False).values.tolist()) + +#瀹炰緥鍖栦竴涓椂闂村簭鍒楃殑瀵硅薄 +timeline = Timeline() +#鎾斁鍙傛暟:璁剧疆鏃堕棿闂撮殧1s 鍗曚綅鏄細ms(姣) +timeline.add_schema(play_interval=1000) + +#寰幆閬嶅巻df_agg['month']閲岀殑鍞竴鍊 +for month in js_agg1['month'].unique(): + data1 = ( + js_agg1[js_agg1['month'] == month][['tianqi', 'count']] + .sort_values(by='count', ascending=True) + .values.tolist() + ) + + # print(data) #缁樺埗鏌辩姸鍥 + bar1 = Bar() + # x杞存槸澶╂皵鍚嶇О + bar1.add_xaxis([x[0] for x in data1]) + # y杞存槸鍚勫ぉ姘斿嚭鐜版鏁 + bar1.add_yaxis('澶╂皵鎯呭喌', [x[1] for x in data1]) + + # 璁╂煴鐘跺浘妯潃鏀 + bar1.reversal_axis() + # 灏嗚鏁版爣绛炬斁鍦ㄥ浘褰㈠彸杈 + bar1.set_series_opts(label_opts=opts.LabelOpts(position='right')) + # 璁剧疆涓嬪浘琛ㄧ殑鍚嶅瓧 + bar1.set_global_opts(title_opts=opts.TitleOpts(title='闀挎矙2023骞存瘡鏈堝ぉ姘斿彉鍖')) + # 灏嗚缃ソ鐨刡ar瀵硅薄鏀剧疆鍒版椂闂磋疆鎾浘涓紝骞朵笖鏍囩閫夋嫨鏈堜唤 鏍煎紡涓猴細鏁板瓧鏈 + timeline.add(bar1, f'{month}鏈') + timeline.render('闀挎矙澶╂皵杞挱鍥.html') diff --git a/Weather_Visual/WindShow.py b/Weather_Visual/WindShow.py new file mode 100644 index 0000000..917574e --- /dev/null +++ b/Weather_Visual/WindShow.py @@ -0,0 +1,47 @@ +# -*- coding: gbk -*- +import pandas as pd +from pyecharts import options as opts +from pyecharts.charts import Pie, Bar, Timeline + +df = pd.read_csv('changsha天气.csv', encoding='gbk') + +df['日期'] = df['日期'].apply(lambda x: pd.to_datetime(x)) + +df['month'] = df['日期'].dt.month +df_agg = df.groupby(['month', '风向/风速']).size().reset_index() + +df_agg.columns = ['month', 'fengsu', 'count'] + +print(df_agg[df_agg['month'] == 1][['fengsu', 'count']] \ + .sort_values(by='count', ascending=False).values.tolist()) + +#实例化一个时间序列的对象 +timeline = Timeline() +#播放参数:设置时间间隔1s 单位是:ms(毫秒) +timeline.add_schema(play_interval=1000) + +#循环遍历df_agg['month']里的唯一值 + + +for month in df_agg['month'].unique(): + data = ( + df_agg[df_agg['month'] == month][['fengsu', 'count']] + .sort_values(by='count', ascending=True) + .values.tolist() + ) + + bar = Bar() + # x轴是天气名称 + bar.add_xaxis([x[0] for x in data]) + # y轴是各天气出现次数 + bar.add_yaxis('风向/风速情况', [x[1] for x in data]) + + # 让柱状图横着放 + bar.reversal_axis() + # 将计数标签放在图形右边 + bar.set_series_opts(label_opts=opts.LabelOpts(position='right')) + # 设置下图表的名字 + bar.set_global_opts(title_opts=opts.TitleOpts(title='长沙2023年每月风向变化')) + # 将设置好的bar对象放置到时间轮播图中,并且标签选择月份 格式为:数字月 + timeline.add(bar, f'{month}月') + timeline.render('长沙风速风向轮播图.html') diff --git a/Weather_Visual/bingtu.py b/Weather_Visual/bingtu.py new file mode 100644 index 0000000..9f3b554 --- /dev/null +++ b/Weather_Visual/bingtu.py @@ -0,0 +1,40 @@ +# -*- coding: GBK -*- +import pandas as pd +import matplotlib.pyplot as plt +from matplotlib.font_manager import FontProperties + +plt.rcParams['font.sans-serif'] = ['SimHei'] # 用黑体显示中文 +plt.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题 + +data = pd.read_csv('changsha天气.csv', encoding='GBK')['天气'].tolist() +# 统计天气种类及次数 +weather_counts = {} +for weather in data: + if weather in weather_counts: + weather_counts[weather] += 1 + else: + weather_counts[weather] = 1 + +# 绘制饼图 +plt.figure(figsize=(15,15 )) + +threshold = 0.05 # 设定显示阈值为5% + +def custom_autopct(pct): + """ + 自定义autopct逻辑,用于控制百分比标签的显示。 + 如果百分比小于阈值,则返回空字符串(即不显示标签)。 + """ + return ('%1.1f%%' % pct) if pct >= threshold else '' + +labels_to_show = [label for label, count in weather_counts.items() if count/sum(weather_counts.values()) >= threshold] +values_to_show = [count for label, count in weather_counts.items() if label in labels_to_show] + +legend_labels = [label for label in weather_counts.keys() if label in labels_to_show] + +patches, texts, autotexts = plt.pie(weather_counts.values(), autopct=custom_autopct, startangle=140) +plt.legend(patches,weather_counts.keys(), title="Weather Types", loc="center left", bbox_to_anchor=(1, 0, 0.5, 1)) + +plt.title('Weather Distribution') +plt.savefig('长沙2023年气温饼图.png') +plt.show() diff --git a/Weather_Visual/changsha澶╂皵.csv b/Weather_Visual/changsha澶╂皵.csv new file mode 100644 index 0000000..7e9900d --- /dev/null +++ b/Weather_Visual/changsha澶╂皵.csv @@ -0,0 +1,362 @@ +日期,最高气温,最低气温,天气,风向/风速 +2023-01-01,10,5,多云,北风 1级 +2023-01-02,9,5,多云,西北风 1级 +2023-01-03,13,3,多云,东南风 1级 +2023-01-04,13,5,晴,东北风 1级 +2023-01-05,15,6,多云,北风 2级 +2023-01-06,17,3,晴,东北风 1级 +2023-01-07,19,5,晴,东南风 3级 +2023-01-08,21,7,晴,东南风 3级 +2023-01-09,18,7,晴,西风 1级 +2023-01-10,14,6,晴,北风 2级 +2023-01-11,17,13,晴,南风 3级 +2023-01-12,18,13,阴,东风 1级 +2023-01-13,19,7,阴,南风 1级 +2023-01-14,8,0,阴,北风 2级 +2023-01-15,1,-1,阴,北风 1级 +2023-01-16,2,0,阴,北风 2级 +2023-01-17,7,1,雨夹雪,西风 1级 +2023-01-18,11,2,晴,西风 1级 +2023-01-19,13,2,多云,西风 1级 +2023-01-20,9,5,多云,西北风 3级 +2023-01-21,9,7,多云,西北风 2级 +2023-01-22,7,4,小雨,西北风 1级 +2023-01-23,6,1,阴,北风 2级 +2023-01-24,9,-1,晴,东北风 2级 +2023-01-25,9,0,晴,东风 2级 +2023-01-26,8,3,多云,北风 2级 +2023-01-27,12,-2,晴,北风 2级 +2023-01-28,12,-3,晴,西北风 1级 +2023-01-29,15,-1,晴,东南风 2级 +2023-01-30,17,3,晴,东南风 2级 +2023-01-31,22,7,晴,东南风 1级 +2023-02-01,13,8,晴,北风 3级 +2023-02-02,7,4,多云,西北风 1级 +2023-02-03,4,3,阴,北风 1级 +2023-02-04,5,4,阴,西北风 2级 +2023-02-05,7,5,阴,西风 2级 +2023-02-06,8,5,阴,西北风 2级 +2023-02-07,9,8,阴,西北风 1级 +2023-02-08,10,9,阴,西北风 2级 +2023-02-09,7,5,阴,西北风 1级 +2023-02-10,7,6,阴,西南风 2级 +2023-02-11,10,6,小雨,西北风 3级 +2023-02-12,8,6,阴,西北风 3级 +2023-02-13,6,3,多云,北风 2级 +2023-02-14,6,0,多云,西北风 2级 +2023-02-15,12,1,晴,南风 1级 +2023-02-16,11,4,多云,西风 1级 +2023-02-17,11,10,多云,东南风 2级 +2023-02-18,16,9,多云,西北风 2级 +2023-02-19,18,5,多云,西北风 1级 +2023-02-20,19,7,晴,西北风 3级 +2023-02-21,17,6,多云,西北风 2级 +2023-02-22,8,7,多云,北风 2级 +2023-02-23,7,5,多云,西北风 3级 +2023-02-24,11,4,多云,北风 2级 +2023-02-25,14,1,晴,东北风 2级 +2023-02-26,16,4,晴,东风 2级 +2023-02-27,18,6,晴,东风 2级 +2023-02-28,16,9,阴,北风 2级 +2023-03-01,18,10,多云,西北风 3级 +2023-03-02,21,11,晴~阴,东风 1级 +2023-03-03,15,7,多云~晴,南风 2级 +2023-03-04,19,7,多云~晴,东南风 2级 +2023-03-05,24,11,晴,东南风 2级 +2023-03-06,26,12,晴~多云,东风 2级 +2023-03-07,24,16,多云~小雨,西北风 3级 +2023-03-08,18,13,多云,东南风 2级 +2023-03-09,23,13,多云~晴,东风 1级 +2023-03-10,27,15,多云~中雨,西北风 3级 +2023-03-11,22,14,多云,北风 3级 +2023-03-12,19,10,阴~多云,北风 3级 +2023-03-13,21,8,多云~晴,南风 2级 +2023-03-14,25,14,晴~小雨,西北风 3级 +2023-03-15,28,14,多云,东风 1级 +2023-03-16,16,7,多云~中雨,北风 4级 +2023-03-17,7,6,小雨~阴,北风 2级 +2023-03-18,9,8,小雨,西北风 3级 +2023-03-19,9,8,中雨~小雨,北风 1级 +2023-03-20,11,10,多云~小雨,北风 2级 +2023-03-21,13,9,小雨,西北风 2级 +2023-03-22,14,11,小雨,西北风 2级 +2023-03-23,14,9,小雨,西北风 1级 +2023-03-24,10,9,小雨,西北风 3级 +2023-03-25,12,6,小雨~多云,西北风 2级 +2023-03-26,17,10,多云~阴,西北风 2级 +2023-03-27,14,9,小雨~阴,北风 1级 +2023-03-28,16,12,多云~小雨,东南风 2级 +2023-03-29,14,11,小雨~多云,北风 1级 +2023-03-30,20,12,多云~小雨,东风 1级 +2023-03-31,24,11,多云~小雨,东南风 2级 +2023-04-01,27,16,多云,东南风 2级 +2023-04-02,26,19,多云,东南风 4级 +2023-04-03,27,15,小雨~暴雨,南风 4级 +2023-04-04,15,12,中雨~阴,西北风 3级 +2023-04-05,16,12,阴~小雨,北风 3级 +2023-04-06,16,8,中雨~晴,北风 4级 +2023-04-07,22,12,晴~多云,东北风 2级 +2023-04-08,24,10,多云~晴,东北风 1级 +2023-04-09,25,14,晴~多云,东南风 2级 +2023-04-10,24,18,多云~阴,南风 3级 +2023-04-11,28,17,多云~小雨,南风 1级 +2023-04-12,29,19,多云~小雨,东南风 1级 +2023-04-13,29,20,多云~大雨,南风 2级 +2023-04-14,24,15,阴~多云,西北风 3级 +2023-04-15,28,15,多云~晴,西北风 2级 +2023-04-16,32,20,晴,南风 3级 +2023-04-17,33,21,多云~大雨,南风 4级 +2023-04-18,22,20,暴雨~小雨,东南风 2级 +2023-04-19,28,20,多云,北风 3级 +2023-04-20,31,20,晴~多云,东北风 1级 +2023-04-21,31,17,多云~小雨,东南风 3级 +2023-04-22,14,9,小雨~中雨,西北风 4级 +2023-04-23,12,9,小雨,西北风 3级 +2023-04-24,12,10,小雨,西北风 3级 +2023-04-25,19,9,阴~晴,西北风 2级 +2023-04-26,25,11,多云,东南风 2级 +2023-04-27,21,18,多云~小雨,东南风 3级 +2023-04-28,20,15,中雨~小雨,东北风 1级 +2023-04-29,23,10,阴~晴,北风 2级 +2023-04-30,28,11,多云~晴,东南风 2级 +2023-05-01,29,18,晴~多云,东风 2级 +2023-05-02,26,24,多云,东南风 1级 +2023-05-03,30,24,多云,南风 4级 +2023-05-04,33,22,多云~中雨,西北风 1级 +2023-05-05,26,18,多云~大雨,西风 1级 +2023-05-06,19,15,中雨~小雨,西北风 4级 +2023-05-07,20,16,阴~多云,西北风 1级 +2023-05-08,26,13,多云,东北风 2级 +2023-05-09,26,18,多云~小雨,东北风 2级 +2023-05-10,17,15,大雨~小雨,西北风 3级 +2023-05-11,20,13,多云~晴,西风 1级 +2023-05-12,27,15,多云~晴,南风 1级 +2023-05-13,27,18,多云,东南风 1级 +2023-05-14,29,18,多云,南风 2级 +2023-05-15,30,21,多云~小雨,东南风 1级 +2023-05-16,29,22,多云~中雨,东南风 1级 +2023-05-17,29,18,阴~多云,西风 1级 +2023-05-18,32,21,多云~晴,西风 1级 +2023-05-19,34,23,多云~小雨,北风 1级 +2023-05-20,29,22,阴~中雨,东风 1级 +2023-05-21,29,15,小雨,西北风 3级 +2023-05-22,18,15,雾~阴,西北风 2级 +2023-05-23,24,17,小雨,西北风 1级 +2023-05-24,27,19,多云,南风 2级 +2023-05-25,29,23,多云~中雨,东南风 1级 +2023-05-26,33,26,多云,东南风 2级 +2023-05-27,34,26,多云~晴,东北风 2级 +2023-05-28,36,25,晴,东南风 2级 +2023-05-29,35,25,多云~晴,西北风 1级 +2023-05-30,27,24,多云,西北风 2级 +2023-05-31,29,24,多云,西北风 2级 +2023-06-01,30,23,多云,北风 2级 +2023-06-02,33,24,多云~小雨,北风 2级 +2023-06-03,29,23,多云,西北风 2级 +2023-06-04,31,22,多云~晴,北风 3级 +2023-06-05,26,20,小雨,西北风 1级 +2023-06-06,28,21,多云,北风 1级 +2023-06-07,33,23,阴~大雨,西北风 2级 +2023-06-08,30,24,多云,南风 1级 +2023-06-09,33,24,多云~晴,北风 2级 +2023-06-10,32,25,晴~多云,东南风 1级 +2023-06-11,36,24,多云,东北风 2级 +2023-06-12,34,23,多云~小雨,北风 2级 +2023-06-13,28,21,多云,东南风 2级 +2023-06-14,30,21,多云~阴,东北风 1级 +2023-06-15,29,24,多云~阴,东北风 2级 +2023-06-16,31,24,多云~小雨,东风 3级 +2023-06-17,34,25,多云~阴,南风 3级 +2023-06-18,34,27,多云~小雨,南风 1级 +2023-06-19,33,24,多云~大雨,西北风 2级 +2023-06-20,27,24,暴雨~中雨,东南风 2级 +2023-06-21,34,23,多云~大雨,北风 1级 +2023-06-22,22,21,大雨~小雨,东南风 1级 +2023-06-23,25,21,小雨,西风 1级 +2023-06-24,26,22,中雨~小雨,西南风 1级 +2023-06-25,28,23,小雨~多云,南风 1级 +2023-06-26,31,25,雾~晴,南风 2级 +2023-06-27,33,24,阴,东南风 1级 +2023-06-28,34,26,阴,南风 1级 +2023-06-29,34,27,阴,南风 2级 +2023-06-30,32,26,阴,西北风 1级 +2023-07-01,35,27,多云,东南风 2级 +2023-07-02,36,28,多云~晴,东南风 1级 +2023-07-03,35,28,多云~晴,东南风 3级 +2023-07-04,34,26,大雨~中雨,北风 1级 +2023-07-05,34,28,多云,南风 2级 +2023-07-06,36,30,多云~晴,南风 3级 +2023-07-07,36,29,多云,南风 2级 +2023-07-08,35,28,多云~晴,东南风 2级 +2023-07-09,36,28,晴,南风 2级 +2023-07-10,36,28,多云~晴,东南风 1级 +2023-07-11,36,29,多云~晴,南风 3级 +2023-07-12,36,30,多云~晴,东风 1级 +2023-07-13,37,30,多云,东南风 1级 +2023-07-14,32,26,阴~小雨,北风 2级 +2023-07-15,33,26,阴~多云,北风 2级 +2023-07-16,35,26,阴~多云,北风 3级 +2023-07-17,31,25,小雨,西北风 1级 +2023-07-18,34,26,阴~小雨,南风 5级 +2023-07-19,35,26,阴~小雨,东风 1级 +2023-07-20,35,26,阴~小雨,西南风 1级 +2023-07-21,36,27,阴,南风 2级 +2023-07-22,34,26,中雨,东南风 2级 +2023-07-23,33,26,阴~晴,东南风 2级 +2023-07-24,36,27,阴~多云,东南风 1级 +2023-07-25,34,26,阴~多云,东南风 1级 +2023-07-26,36,26,阴~多云,北风 3级 +2023-07-27,35,26,阴~多云,北风 2级 +2023-07-28,36,25,阴~小雨,北风 1级 +2023-07-29,34,26,小雨~多云,西北风 2级 +2023-07-30,35,26,中雨~阴,南风 3级 +2023-07-31,35,26,阴~多云,南风 2级 +2023-08-01,33,26,阴~多云,东南风 1级 +2023-08-02,33,26,小雨~多云,东风 2级 +2023-08-03,37,27,阴~晴,东北风 1级 +2023-08-04,38,27,阴~晴,南风 1级 +2023-08-05,37,29,多云~晴,南风 2级 +2023-08-06,37,28,阴~多云,东南风 2级 +2023-08-07,35,26,阴~小雨,西北风 2级 +2023-08-08,36,26,阴~小雨,西北风 2级 +2023-08-09,35,27,小雨~多云,北风 2级 +2023-08-10,35,27,阴~晴,西北风 3级 +2023-08-11,36,26,阴~多云,东南风 1级 +2023-08-12,37,26,阴~多云,东南风 2级 +2023-08-13,31,26,中雨~小雨,西北风 2级 +2023-08-14,33,26,阴~晴,西北风 2级 +2023-08-15,34,25,小雨~晴,西北风 1级 +2023-08-16,36,25,阴~多云,西北风 1级 +2023-08-17,37,26,阴~多云,东北风 2级 +2023-08-18,37,27,多云,东北风 1级 +2023-08-19,36,26,阴,北风 1级 +2023-08-20,36,27,阴,西北风 1级 +2023-08-21,30,25,阴~大雨,西南风 2级 +2023-08-22,35,25,阴~晴,北风 2级 +2023-08-23,36,25,阴~晴,东风 2级 +2023-08-24,35,26,阴~多云,西北风 1级 +2023-08-25,35,26,阴~多云,东北风 2级 +2023-08-30,28,22,小雨转多云,北风 2级 +2023-08-31,30,22,多云转晴,北风 2级 +2023-09-01,33,23,阴~晴,北风 3级 +2023-09-02,29,23,阴~小雨,西北风 3级 +2023-09-03,27,20,小雨~多云,西北风 3级 +2023-09-04,30,24,多云~晴,北风 3级 +2023-09-05,32,25,阴~多云,西北风 3级 +2023-09-06,32,25,小雨~多云,西北风 2级 +2023-09-07,34,25,阴~多云,东北风 2级 +2023-09-08,35,26,多云,东北风 2级 +2023-09-09,36,26,阴~晴,东北风 2级 +2023-09-10,36,26,多云~晴,东南风 1级 +2023-09-11,35,25,多云,东南风 2级 +2023-09-12,27,22,阴~小雨,西北风 3级 +2023-09-13,23,22,小雨~中雨,西北风 3级 +2023-09-14,26,22,小雨~阴,西北风 2级 +2023-09-15,30,22,小雨~多云,东南风 1级 +2023-09-16,32,23,多云~晴,东南风 1级 +2023-09-17,34,25,多云~晴,南风 2级 +2023-09-18,36,27,阴~晴,东南风 3级 +2023-09-19,35,26,阴~多云,南风 3级 +2023-09-20,25,21,阴~小雨,西北风 4级 +2023-09-21,21,19,阴~小雨,西北风 3级 +2023-09-22,20,19,小雨~阴,北风 3级 +2023-09-23,23,22,阴~多云,西北风 2级 +2023-09-24,24,21,阴~多云,西北风 3级 +2023-09-25,22,21,阴,西北风 3级 +2023-09-26,25,22,阴,西北风 2级 +2023-09-27,27,23,阴,西北风 2级 +2023-09-28,30,23,阴~晴,西北风 2级 +2023-09-29,30,23,阴~晴,西北风 2级 +2023-09-30,25,22,阴~小雨,西北风 3级 +2023-10-01,23,22,阴,北风 2级 +2023-10-02,25,20,阴,西北风 2级 +2023-10-03,19,18,阴,西北风 3级 +2023-10-04,22,18,阴~小雨,西北风 3级 +2023-10-05,23,18,阴,西北风 3级 +2023-10-06,23,17,阴~小雨,西北风 4级 +2023-10-07,19,16,小雨,西北风 3级 +2023-10-08,22,18,阴~小雨,西北风 3级 +2023-10-09,22,17,阴,北风 2级 +2023-10-10,22,16,小雨,北风 2级 +2023-10-11,26,16,多云,东北风 2级 +2023-10-12,23,18,阴,西北风 3级 +2023-10-13,23,16,阴,西北风 3级 +2023-10-14,27,14,阴~晴,西北风 2级 +2023-10-15,29,15,晴,东风 1级 +2023-10-16,30,15,晴,东南风 2级 +2023-10-17,30,15,晴,东南风 3级 +2023-10-18,32,21,晴~多云,东南风 2级 +2023-10-19,24,16,阴~小雨,西北风 3级 +2023-10-20,23,12,多云,东北风 3级 +2023-10-21,24,13,晴~多云,北风 1级 +2023-10-22,26,14,晴,东北风 1级 +2023-10-23,28,16,晴,东南风 2级 +2023-10-24,31,19,阴~多云,东南风 1级 +2023-10-25,24,18,阴~大雨,北风 3级 +2023-10-26,22,19,小雨,西北风 2级 +2023-10-27,22,17,阴~小雨,西北风 2级 +2023-10-28,21,16,阴,西北风 2级 +2023-10-29,26,15,晴,西北风 1级 +2023-10-30,28,17,晴,东北风 1级 +2023-10-31,29,15,多云~晴,东南风 2级 +2023-11-01,28,15,多云~晴,东南风 2级 +2023-11-02,29,17,晴,南风 2级 +2023-11-03,28,15,阴,东南风 2级 +2023-11-04,19,16,阴,西北风 2级 +2023-11-05,29,12,阴~小雨,西北风 2级 +2023-11-06,23,11,阴~晴,北风 2级 +2023-11-07,24,13,晴~小雨,东南风 2级 +2023-11-08,20,16,小雨~中雨,东南风 2级 +2023-11-09,19,14,大雨~小雨,西北风 1级 +2023-11-10,16,10,小雨,西北风 4级 +2023-11-11,9,7,中雨~小雨,西北风 4级 +2023-11-12,8,7,小雨,西北风 3级 +2023-11-13,10,6,阴~多云,西北风 3级 +2023-11-14,17,10,晴~阴,西北风 1级 +2023-11-15,17,7,小雨,西北风 2级 +2023-11-16,17,4,多云~晴,北风 3级 +2023-11-17,21,7,晴,北风 1级 +2023-11-18,21,12,阴~晴,东风 1级 +2023-11-19,23,9,阴~晴,东南风 2级 +2023-11-20,25,10,晴,东南风 1级 +2023-11-21,24,11,晴,东南风 2级 +2023-11-22,25,13,阴~晴,南风 2级 +2023-11-23,25,9,阴~多云,北风 3级 +2023-11-24,18,8,阴~晴,西北风 3级 +2023-11-25,15,9,阴,西北风 1级 +2023-11-26,13,5,阴~多云,西北风 2级 +2023-11-27,21,7,晴,东北风 1级 +2023-11-28,22,8,晴,东南风 2级 +2023-11-29,22,8,多云~阴,北风 2级 +2023-11-30,9,4,阴,西北风 4级 +2023-12-01,14,8,晴~多云,北风 2级 +2023-12-02,11,9,阴,西风 1级 +2023-12-03,10,8,小雨,北风 1级 +2023-12-04,18,6,阴~晴,西南风 1级 +2023-12-05,19,9,晴~多云,东南风 2级 +2023-12-06,22,7,多云~晴,北风 3级 +2023-12-07,23,10,晴,南风 3级 +2023-12-08,21,15,阴~小雨,东南风 3级 +2023-12-09,21,15,阴,东南风 3级 +2023-12-10,18,7,阴~小雨,西北风 2级 +2023-12-11,7,3,阴~小雨,西北风 4级 +2023-12-12,11,5,阴~多云,北风 2级 +2023-12-13,13,10,多云,东南风 3级 +2023-12-14,12,4,多云~小雨,西北风 2级 +2023-12-15,5,1,阴~雨夹雪,北风 5级 +2023-12-16,6,2,阴,北风 4级 +2023-12-17,4,1,阴~雨夹雪,北风 2级 +2023-12-18,2,0,雨夹雪,西北风 2级 +2023-12-19,4,0,雨夹雪~多云,西北风 2级 +2023-12-20,5,0,阴~多云,北风 2级 +2023-12-21,7,-3,阴~晴,北风 4级 +2023-12-22,8,-3,晴,北风 3级 +2023-12-23,9,-2,多云~晴,西北风 1级 +2023-12-24,11,-1,晴,西北风 2级 +2023-12-25,15,2,晴,东南风 1级 +2023-12-26,17,5,多云~晴,东南风 2级 +2023-12-27,16,5,晴~多云,西北风 2级 +2023-12-28,15,5,晴~多云,西北风 2级 +2023-12-29,14,7,阴~小雨,西北风 2级 +2023-12-30,17,7,阴~晴,西南风 1级 +2023-12-31,18,5,晴~小雨,西北风 2级 diff --git a/Weather_Visual/mysql_connect.py b/Weather_Visual/mysql_connect.py new file mode 100644 index 0000000..932bc14 --- /dev/null +++ b/Weather_Visual/mysql_connect.py @@ -0,0 +1,35 @@ +# -*- coding: gbk -*- +from typing import List + +import mysql +import mysql.connector +import csv + +db_config = { + 'host': 'localhost', + 'user': 'root', + 'password': '21412030115', + 'database': '长沙天气', +} + +cnx = mysql.connector.connect(**db_config) +cursor = cnx.cursor() + +# 读取CSV +with open('changsha天气.csv', mode='r', encoding='gbk') as file: + reader = csv.reader(file) + headers = next(reader, None) + if headers is not None: # 过表头 + for row in reader: + sql = "INSERT IGNORE INTO 长沙天气(date, high_temperature, low_temperature, weather,fengsu) VALUES (%s, %s, %s, %s,%s)" + cursor.execute(sql, (row[0], row[1], row[2], row[3], row[4])) #设csv与数据库对应 + +try: + + cnx.commit() + print("数据导入成功!") +except mysql.connector.Error as err: + print(f"数据导入失败: {err}") +finally: + cursor.close() + cnx.close() diff --git a/Weather_Visual/spliet.py b/Weather_Visual/spliet.py new file mode 100644 index 0000000..9ddbe49 --- /dev/null +++ b/Weather_Visual/spliet.py @@ -0,0 +1,45 @@ +import mysql.connector +import csv + +# MySQL数据库配置 +db_config = { + 'host': 'localhost', + 'user': 'root', + 'password': '21412030115', + 'database': '长沙天气' +} + +# 连接到MySQL数据库 +cnx = mysql.connector.connect(**db_config) +cursor = cnx.cursor() + +# 创建表(如果尚未创建) +# cursor.execute(""" +# CREATE TABLE IF NOT EXISTS weather_data ( +# id INT AUTO_INCREMENT PRIMARY KEY, +# date DATE, +# high_temperature FLOAT, +# low_temperature FLOAT, +# weather VARCHAR(255), +# wind_direction VARCHAR(255) +# ) +# """) + +# CSV文件路径 +csv_file_path = 'changsha天气.csv' + +# 读取CSV文件并插入数据 +with open(csv_file_path, mode='r', encoding='gbk') as csvfile: + csv_reader = csv.reader(csvfile) + next(csv_reader) # 跳过表头 + for row in csv_reader: + sql = "INSERT INTO weather_data (date, high_temperature, low_temperature, weather, wind_direction) VALUES (%s, %s, %s, %s, %s)" + cursor.execute(sql, row) + +# 提交事务 +cnx.commit() +print("数据导入成功!") + +# 关闭连接 +cursor.close() +cnx.close() \ No newline at end of file diff --git a/Weather_Visual/闀挎矙2023骞存皵娓╂姌绾垮浘.png b/Weather_Visual/闀挎矙2023骞存皵娓╂姌绾垮浘.png new file mode 100644 index 0000000..550e8df Binary files /dev/null and b/Weather_Visual/闀挎矙2023骞存皵娓╂姌绾垮浘.png differ diff --git a/Weather_Visual/闀挎矙2023骞存皵娓╅ゼ鍥.png b/Weather_Visual/闀挎矙2023骞存皵娓╅ゼ鍥.png new file mode 100644 index 0000000..e739dcf Binary files /dev/null and b/Weather_Visual/闀挎矙2023骞存皵娓╅ゼ鍥.png differ diff --git a/Weather_Visual/闀挎矙澶╂皵杞挱鍥.html b/Weather_Visual/闀挎矙澶╂皵杞挱鍥.html new file mode 100644 index 0000000..ae50b44 --- /dev/null +++ b/Weather_Visual/闀挎矙澶╂皵杞挱鍥.html @@ -0,0 +1,2022 @@ + + +
+ +