I have two large data frames df1 & df2
df1
ID ...other columns...MON TUE WED THU FRI SAT SUN
1 8.5 8.5 8.5 8.5 8.5 6.0 0.0
2 9.0 9.0 9.0 9.0 9.0 6.0 6.0
4 6.0 7.0 7.0 7.0 7.0 5.0 0.0
df2
Day Hours
FRI 0
SAT 0
SUN 0
MON 0
TUE 0
WED 0
THU 0
FRI 0
SAT 0
SUN 0
MON 0
TUE 0
WED 0
...Will keep going until end about 28-31 days listed
I am trying to replace the Hours column in df2 with the corresponding times in df1 (Matching df1 column day names with the names in the day column in df2). df2 would fill using the first row of data in df1 until all rows in df2 have been filled then move onto the next row (loop through)...the idea being once 1st row has been filled, before moving onto the next, I would do a Sum of the 'Hours' column in df2 and then put that number back in df1 in a seperate column next to first row and so on...
df2 1st output
Day Hours
FRI 8.5
SAT 6.0
SUN 0
MON 8.5
TUE 8.5
WED 8.5
THU 8.5
FRI 8.5
SAT 6.0
SUN 0
MON 8.5
TUE 8.5
WED 8.5
...will continue all the way until last row until all data is filled from 1st row in df1 (repeating itself, just matching the right values with rows)
df1 1st output
ID ...other columns...MON TUE WED THU FRI SAT SUN Total
1 8.5 8.5 8.5 8.5 8.5 6.0 0.0 88.5
2 9.0 9.0 9.0 9.0 9.0 6.0 6.0
4 6.0 7.0 7.0 7.0 7.0 5.0 0.0
...notice the Total is only from the Hours column in df2 which is only populated from data in the the corresponding row
df2 2nd output
Day Hours
FRI 9.0
SAT 6.0
SUN 6.0
MON 9.0
TUE 9.0
WED 9.0
THU 9.0
FRI 9.0
SAT 6.0
SUN 6.0
MON 9.0
TUE 9.0
WED 9.0
...once first row in df1 has filled all df2 and a sum has been made then it would clean the Hours column and refill but now with row 2 of df1...doing the same thing until all rows in df2 has been filled
df1 2nd output
ID ...other columns...MON TUE WED THU FRI SAT SUN Total
1 8.5 8.5 8.5 8.5 8.5 6.0 0.0 88.5
2 9.0 9.0 9.0 9.0 9.0 6.0 6.0 105
4 6.0 7.0 7.0 7.0 7.0 5.0 0.0
...notice now the Total is only from the Hours column in df2 which is only populated from data in the the corresponding row
This continues for every line in df1 - which is about 1400 lines
So I am trying to sort out the matching/looping part of this but can't seem to get to a solution that works. Is there a way of doing this? I have been suggested using Matches, Joins, Left, Right Outer etc...but I am unsure how this would be used without a unique number ID and how would loop through the data frame
Many thanks