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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 30 18:34:46 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 ( )
riqi = input ( ' 请输入要查询的日期( 如2022-12-01) : ' )
df1 = df [ df . date == riqi ]
#print(df1)
plt . rcParams [ ' font.sans-serif ' ] = [ ' SimHei ' ]
plt . rcParams [ ' figure.figsize ' ] = ( 10 , 5 )
flightnumber = { }
x = df1 [ ' flightNum ' ]
y = df1 [ ' depTime ' ]
lst_x = x . values . tolist ( )
lst_y = y . values . tolist ( )
morning = [ ]
noon = [ ]
night = [ ]
for i in lst_y :
a = int ( lst_y [ 0 ] [ 0 : 2 ] )
if 8 < = a < = 12 :
morning . append ( 0 )
elif 12 < a < = 17 :
noon . append ( 0 )
else :
night . append ( 0 )
x = [ ' 8:00-12:00 ' , ' 12:00-17:00 ' , ' 17:00-8:00 ' ]
y = [ len ( morning ) , len ( noon ) , len ( night ) ]
print ( y )
plt . bar ( x , y , linestyle = " -- " , hatch = " / " , color = ' maroon ' )
plt . xlabel ( " 时段 " , fontsize = 14 )
plt . ylabel ( " 航班数目 " , fontsize = 14 )
tit = riqi + ' 航班出发时间对照图 '
plt . title ( tit , fontsize = ' xx-large ' , color = ' lightseagreen ' )
plt . show ( )