简体   繁体   English

如何标记学生在场/缺席python

[英]How to mark a student present/absent python

I am trying to mark users present/absent based on their last login timestamp.我正在尝试根据上次登录时间戳标记用户存在/不存在。 If the users logged in on 9/3/2020 at midnight and before 9:05am they are marked present otherwise they are absent.如果用户在 2020 年 9 月 3 日午夜和上午 9 点 05 分之前登录,他们将被标记为出席,否则他们将缺席。

Student Timestamp example学生时间戳示例

Time                            Present/Absent
2020-09-03T08:55:14-05:00          present
2020-09-03T04:44:46-05:00          present
2020-09-03T09:01:05-05:00          present
2020-09-03T07:12:22-05:00          present
2020-09-03T08:48:53-05:00          present
2020-09-02T16:53:20-05:00          absent
2020-09-02T20:02:28-05:00          absent
2020-09-03T09:01:15-05:00          present
2020-09-03T08:55:03-05:00          present
2020-09-03T09:03:03-05:00          present
2020-09-02T09:13:32-05:00          absent
2020-09-02T23:24:54-05:00          absent
2020-09-02T23:24:58-05:00          absent
2020-09-03T09:03:03-05:00          present
2020-09-02T23:25:01-05:00          absent



This is my code这是我的代码


df3['Time'] = df3['Time'].astype(str)

for time in df3['Time']:
    if time > '%Y-%m-%d 00:00:00-05:00':
        df3['Present/Absent'] = 'absent'
    elif  time < '%Y-%m-%d 09:05:00-05:00':
        df3['Present/Absent'] = 'present'

but I get this但我明白了

Time                        Present/Absent
2020-09-03T08:55:14-05:00     present
2020-09-03T04:44:46-05:00     present
2020-09-03T09:01:05-05:00     present
2020-09-03T07:12:22-05:00     present
2020-09-03T08:48:53-05:00     present
2020-09-02T16:53:20-05:00     present
2020-09-02T20:02:28-05:00     present
2020-09-03T09:01:15-05:00     present
2020-09-03T08:55:03-05:00     present
2020-09-03T09:03:03-05:00     present
2020-09-02T09:13:32-05:00     present
2020-09-02T23:24:54-05:00     present
2020-09-02T23:24:58-05:00     present
2020-09-03T09:03:03-05:00     present
2020-09-02T23:25:01-05:00     present

df3['Present/Absent'] = 'present' is assigning 'present' to the entire column. df3['Present/Absent'] = 'present'将 'present' 分配给整个列。 Same applies for the 'absent' condition as well.这同样适用于“缺席”条件。 Try this:尝试这个:

df3['Time'] = df3['Time'].astype(str)
df3['Present/Absent'] = ''
for idx, row in df3.iterrows():
    time = row['Time']
    if time > '%Y-%m-%d 00:00:00-05:00':
        df3.loc[idx, 'Present/Absent'] = 'absent'
    elif  time < '%Y-%m-%d 09:05:00-05:00':
        df3.loc[idx, 'Present/Absent'] = 'present'

I'm assuming the condition is working as expected and df3 is similar to Student Timestamp example.我假设条件按预期工作并且 df3 类似于 Student Timestamp 示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Python 中查找删除一条学生记录(以 Students Mark 练习为例) - How to find delete a student record in Python (example on a Students Mark exercise) opencv 考勤系统将学生标记为存在于 csv 问题 - opencv attendance system mark student as present in csv problem Python如何按照从高到低的顺序对文件中学生的最终分数行进行排序 - Python how to sort each line of the student's Final Mark in the file according from the highest to lowest Scrapy:当不存在时,如何使有条件的(存在或不存在)XPATH返回值? - Scrapy: How to make a conditional (present or absent) XPATH return values when absent? python 中的学生姓名和标记 class - 定义时出现未定义错误 - Student name and mark class in python - undefined error while it is defined 在python中解析csv并在其他csv中编写,是,存在选择,如果没有选择,则否 - parsing csv in python and writing in other csv, yes is choice present and no if choice absent 我需要一个 python 重新匹配,仅当两个字符串不存在且另外两个字符串存在时 - I need a python re to match only if two strings are absent and two other strings are present 如何检查python中是否缺少测试用例中的第二个参数? - How to check if second argument in test case is absent in python? 如何找到 Python 字典中缺少哪些键? - How can I find which keys are absent from a Python dict? 如何通过命令行将缺少值的列表传递给Python - How to pass a list with an absent value to Python through the command line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM