[英]I want to find an existing col/row and edit it
So I am developing a RFID system for a project.所以我正在为一个项目开发一个RFID系统。 I am writing it on a Raspberry PI running python3.我正在运行 python3 的 Raspberry PI 上编写它。
I have these RFID tags, that you scan, and it will log the information at which it was tagged.我有这些 RFID 标签,你可以扫描它,它会记录它被标记的信息。 That sums up to these columns in excel:这总结了 excel 中的这些列:
"worker_name": "", "date": "", "check_in_time": "", "check_out_time": "", "hours_worked": "" “worker_name”:“”,“日期”:“”,“check_in_time”:“”,“check_out_time”:“”,“hours_worked”:“”
I can fill in all these values at check-in, except for the check_out_time obviously, since that should be filled out the second time the tag is scanned.我可以在签入时填写所有这些值,显然 check_out_time 除外,因为这应该在第二次扫描标签时填写。
So my problem is I have no idea on how I can edit the column, when the tag is scanned for check-out, so the check-out time is also logged in the original column, without creating a new one.所以我的问题是我不知道如何编辑列,当扫描标签以进行签出时,签出时间也记录在原始列中,而无需创建新列。
The code I have as we speak is as follows:我们所说的代码如下:
import pandas as pd
from datetime import datetime
from time import sleep
counter = 1
df = pd.DataFrame(
{
"worker": "",
"date": "",
"check_in_time": "",
"check_out_time": "",
"hours_worked": "",
},
index=[counter],
)
while True:
worker = input("Navn \n")
time_now = datetime.now()
date = time_now.strftime("%m/%d/%Y")
time = time_now.strftime("%H:%M")
month = time_now.strftime("%m")
new_check_in = [worker, date, time, "", "dummy_value"]
df.loc[counter] = new_check_in
df.reset_index(drop=True)
df.to_excel("output.xlsx", index=False)
counter += 1
Output is as follows: Output如下:
worker date check_in_time check_out_time hours_worked
1 Homer Simpson 12/09/2021 02:14 dummy_value
2 Marge Simpson 12/09/2021 02:14 dummy_value
3 Bart Simpson 12/09/2021 02:14 dummy_value
4 Peter Griffin 12/09/2021 02:14 dummy_value
This is a proof of example, since I have not yet implemented the part where u scan the tag, concept should remain the same though.这是一个例子的证明,因为我还没有实现你扫描标签的部分,但概念应该保持不变。
So when worker at index 1, finishes his workday, he checks out with his tag, and the dataframe column storing his information, should be updated with check out time.因此,当索引 1 的工人完成他的工作日时,他会使用他的标签结账,并且存储他的信息的 dataframe 列应该更新结账时间。
Thank you all, kind regards!谢谢大家,亲切的问候!
Assuming that all workers have different names, you could try checking for the worker
/ date
values in their respective columns and fill in the check_out_time
if it appears.假设所有工作人员都有不同的名称,您可以尝试检查其各自列中的worker
/ date
值,如果出现,则填写check_out_time
。
The latter section of your code could looks as follows, for example:您的代码的后一部分可能如下所示,例如:
while True:
worker = input("Navn \n")
time_now = datetime.now()
date = time_now.strftime("%m/%d/%Y")
time = time_now.strftime("%H:%M")
if ((df['worker'] == worker) & (df['date'] == date)).any():
idx = df.iloc[(df['worker'] == worker) & (df['date'] == date)]
df.at[idx, check_out_time] = time
df.at[idx, hours_worked] = time - df.at[idx, check_in_time]
new_check_in = [worker, date, time, "", np.nan]
df.loc[counter] = new_check_in
df.reset_index(drop=True)
df.to_excel("output.xlsx", index=False)
counter += 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.