【发布时间】:2019-08-07 18:01:55
【问题描述】:
我有一个 csv 文件中的员工出勤日志报告,我需要过滤所有迟到的员工出勤(9:30 之后)。
我创建了一个生成出勤率的函数。员工输入他的 ID 并标记出勤。程序从计算机时钟中获取日期和时间,并将出勤情况存储在日志文件中。
#function that generated an attendance
def attandance_log():
dnt = datetime.datetime.now()
dnt_string = dnt.strftime("%d/%m/%Y %H:%M:%S")
empid = input("Enter Your ID :")
empname=input("Enter Your Name :")
df1 = pd.DataFrame(data=[[dnt_string,empid,empname]],columns=["Today's Date & Time", "Employee's ID", "Employee's Name"])
with open('/Users/sapir/Documents/python/final project- employee attandance log/attandance_log.csv', 'a') as f:
df1.to_csv(f, header=False)
return df1
attandance_df= attandance_log()
#the functions that filters all late attendances:
def late_emp_report():
df = pd.read_csv('/Users/sapir/Documents/python/final project- employee attandance log/attandance_log.csv',index_col=0)
#df[1] = pd.to_datetime(df[1], unit='s')
# Add to employees list existing file
#df.loc['29/07/2019 09:30:00': ].head()------->???
#df_filtered = df[(df[1] <= datetime.time(9,30))]------>???
print (df_filtered)
with open('/Users/sapir/Documents/python/final project- employee attandance log/emplist.csv', 'w') as f:
df.to_csv(f, header=False)
return df
late_emp_report()
我不知道如何创建一个文件来显示 9:30 之后的所有出勤情况...
【问题讨论】:
标签: python pandas csv datetime filter