我有一個員工打卡日期串列:

需要將其格式化為不同的表格,例如:

每個新行都必須是一個新日期。我已經開始使用變數,但是我無法遍歷列來獲取 IN 和 OUT 時間。對于初學者來說,一點指導將不勝感激。
代碼:
import pandas as pd
file = pd.read_csv("sample_file.csv")
# save unique employee in array
employeeID = file['EMP ID'].unique()
dates = file['PUNCH DATE'].unique()
punchTimes = []
# print(employeeID)
# print(dates)
# print(file)
for employeeID, dates in file:
謝謝!
uj5u.com熱心網友回復:
方法01
方法02
- df.pivot()
- 以后有時間我會寫代碼
在旁邊
- 因為您的問題是專門關于通過資料框進行迭代的,所以我會注意到,如果您需要實作自定義函式,則應用 lambda 模式很有用
def funk(x): # do something pass df.colum_name.apply(lambda x: funk(x))
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/518313.html
