I have a list of employee punch date:
that needs to be formatted into a different table LIKE:
each new row has to be a new date. I have gotten started with variables, however I am failing at iterating through the columns to get the IN and OUT times. A little guidance would be appreciate for a beginner.
Code:
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:
Thank you!
CodePudding user response:
method 01
-
method 02
- df.pivot()
- I'll code this up later when I have time
aside
- since your question was specifically about iteration through a dataframe I'll note that the apply lambda patter is useful if you need to implement a custom function
def funk(x): # do something pass df.colum_name.apply(lambda x: funk(x))