|
用pandas,参考
- import pandas as pd
- from datetime import datetime
- df=pd.read_excel('2023.4.1--4.30.xlsx')
- df['开始时间']=pd.to_datetime(df['开始时间'],format='%Y-%m-%d %H:%M:%S')
- df['结束时间']=pd.to_datetime(df['结束时间'],format='%Y-%m-%d %H:%M:%S')
- def get_time(x,y):
- if (x.time()>datetime.strptime('19:00','%H:%M').time()) and (y.time()<datetime.strptime('22:00','%H:%M').time()):
- return True
- else:
- return False
- df['ref']=df.apply(lambda x: get_time(x['开始时间'],x['结束时间']),axis=1)
- data=df[df['ref']]
- data.groupby(pd.Grouper(key='开始时间',axis=0,freq='D'))['服务费(元)'].sum()
复制代码 |
|