I have a dataset with employee payroll information (df2). It has a date, job title, shift start time, hours worked.
The goal is to create a dataset (df) which shows how many employees were working at any given hour.
The problem I am facing is that setting the value in a column is not having any effect on the original dataset (df).
data1 = [['2/1/2019','Cashier',0,0,0,0,0,0,0], ['2/2/2019','Cashier',0,0,0,0,0,0,0], ['2/1/2019','Server',0,0,0,0,0,0,0]]
cols1 = ['Date', 'Job'] + list(pd.date_range(pd.to_datetime('2/1/2019 15:00'), periods=7, freq='H'))
df=pd.DataFrame(data1, columns=cols1)
data2=[['2/1/2019', 'Cashier', pd.to_datetime('2/1/2019 16:00'), 5.2]]
cols2=['Date', 'Job', 'Start', 'Hours']
df2=pd.DataFrame(data2, columns=cols2)
def count_shifts(x):
start_time=x['Start']
worked_in_minutes =round(x['Hours']) * 60 + (x['Hours'] - round(x['Hours']))
worked_range_index = pd.date_range(start_time, periods=worked_in_minutes, freq='T')
worked_series = pd.Series(1/60, index=worked_range_index)
worked_series=worked_series.resample('H', label='left').sum()
df.loc[:,list(worked_series.index)] \
[(df['Job']==x['Job']) & (df['Date']==x['Date'])] = worked_series.values
df2.apply(count_shifts, axis=1)
I expect df columns corresponding to the hours 15:00,16:00,17:00,18:00,19:00 to equal 1 and 20:00 to equal .2 But the actual result is that they are still 0
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)