You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.3 KiB
42 lines
1.3 KiB
2 years ago
|
# -*- coding: utf-8 -*-
|
||
|
"""
|
||
|
Created on Fri Dec 2 21:57:14 2022
|
||
|
|
||
|
@author: DELL
|
||
|
"""
|
||
|
|
||
|
import datetime
|
||
|
import pandas as pd
|
||
|
import matplotlib.pyplot as plt
|
||
|
with open('information.txt','r',encoding='utf-8') as fe:
|
||
|
info=fe.read()
|
||
|
lst=info.split(' ')
|
||
|
date1 = datetime.datetime.strptime(lst[2],"%Y-%m-%d")
|
||
|
date2 = date1 + datetime.timedelta(days=int(lst[3]))
|
||
|
df = pd.read_csv("contentt.csv", encoding=('gb2312'),names=["date","flightNum", "depTime", "arrTime", "price"])
|
||
|
df.head()
|
||
|
df1 = df.groupby("date").count()["flightNum"]
|
||
|
plt.rcParams['font.sans-serif'] = ['SimHei']
|
||
|
plt.rcParams['figure.figsize'] = (13, 8)
|
||
|
|
||
|
x=df1.index
|
||
|
pricmax=[]
|
||
|
pricmin=[]
|
||
|
for i in range(int(lst[3])):
|
||
|
date1 = date1 + datetime.timedelta(days=1)
|
||
|
df2=df[df.date==str(date1)[0:10]]
|
||
|
pric=df2['price'].max()
|
||
|
pricm=df2['price'].min()
|
||
|
pricmax.append(pric)
|
||
|
pricmin.append(pricm)
|
||
|
|
||
|
for a, b in zip(df1.index.tolist(), pricmax):
|
||
|
plt.text(a, b, b, ha='center', va='bottom', fontsize=20,color='firebrick')
|
||
|
plt.xlabel("日期",fontsize=14)
|
||
|
plt.ylabel("机票价格",fontsize=14)
|
||
|
plt.plot(x, pricmax, marker="^",color='indianred')
|
||
|
|
||
|
for a, b in zip(df1.index.tolist(), pricmin):
|
||
|
plt.text(a, b, b, ha='center', va='top', fontsize=20,color='teal')
|
||
|
plt.plot(x, pricmin, marker="v",color='skyblue')
|