我有一个csv文件中的员工出勤日志报告,我需要过滤所有迟到的员工出勤(9:30之后)。你知道吗
我创建了一个生成考勤的函数。员工输入身份证并标记出勤情况。程序从计算机时钟获取日期和时间,并将出勤情况存储在日志文件中。你知道吗
#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后。。。你知道吗
您可以一次对整个数据帧应用此窗体中的筛选器:
这将返回一个数据帧,其中包含来自原始数据框的所有行,其中列值
column_to_filter_on
大于some_value
我不喜欢使用
1
作为列标题,而是给它起一个名称-以防止以后与索引混淆。你知道吗当您尝试比较循环时间(9:30)和日期时间时,会遇到一个问题,因此您可以使用
late_flag
引入.apply()
来比较任何日期时间和该日期的9:30。你知道吗相关问题 更多 >
编程相关推荐