简体   繁体   English

我想找到一个现有的 col/row 并编辑它

[英]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.

相关问题 我想在 python 中编辑 csv 中的一行 - I want to edit a row in csv in python 如何用“pos”找到行,col? - How find row, col with "pos"? 如何在 pandas dataframe 中找到行,其中 row_x 的 col1 值 == row_y 的 col2 值? - How can I find rows in a pandas dataframe where value of col1 for row_x == value of col2 for row_y? 我无法在所选列 df[df[col]>0] 的每一行中找到最小值(>0) - i cant find the min value(which is>0) in each row in selected columns df[df[col]>0] 我想在 dataframe 中找到一个特定的字符串,在找到该字符串后,我想从 dataframe 中排除该特定行 - I want to find a particular string in a dataframe and after finding the string, I want to exclude that particular row from the dataframe 熊猫找到带有条件的元素的行名+列名 - pandas find row+col names for elements with condition 使用 row 和 col 在 txt.file 中查找字母 - Use row and col to find a letter in a txt.file 是否有任何 Python/numpy 等效于 Matlab 的 [row,col] = find(X) - Is there any Python/numpy equivalent to Matlab's [row,col] = find(X) 如何从python中的row,col名称中找到excel值? - how to find the excel value from row, col names in python? 使用 100 行和 53 列的数据,我想使用 pandas 从 csv 文件中提取仅包含 true 和 false 的列名称作为数据 - with data of 100 row and 53 col, i want to extract the columns name which contains only true and false as data from the csv file using pandas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM