So, I have the followig data:
table1= {'Date E': ['02/03/2024', '02/03/2024', '02/03/2024', '02/03/2024', '02/03/2024','05/03/2024', '05/03/2024', '05/03/2024', '05/03/2024', '07/03/2024','11/03/2024', '11/03/2024', '05/03/2024', '05/03/2024', '05/03/2024','07/03/2024', '11/03/2024', '11/03/2024' ],'vehicle': ['DPB0329', 'DPB0329', 'DPB0329', 'DPB0329', 'DPB0329','DPB0329', 'DPB0329', 'DPB0329', 'DPB0329', 'DPB0329','DPB0329', 'DPB0329', 'DPB0311', 'DPB0311', 'DPB0311','DPB0311', 'DPB0311', 'DPB0311' ],'Valor': [0.0] * 18 # Inicialize com zeros}table2= {'vehicle': ['DPB0329', 'DPB0329', 'DPB0329', 'DPB0329', 'DPB0329','DPB0329', 'DPB0329', 'DPB0311', 'DPB0311', 'DPB0311','DPB0311' ],'Date A': ['02/03/2024', '03/03/2024', '04/03/2024', '06/03/2024', '08/03/2024','09/03/2024', '11/03/2024', '06/03/2024', '08/03/2024', '09/03/2024','11/03/2024' ],'Value': [ 489.74, 838.70, 710.33, 865.80, 852.14, 1032.73, 506.00, 865.80, 852.14, 1032.73, 506.00 ]}
So what I need with this code:
Basicaly, table1 and table2 are complementary but as you can see, both of them have different dates.
I need to bring the information from table 1 to table2, but with some especifical conditions:
*There is a motive for the repetitive infos from table1, I can't delete any of the lines.
*Information with D-1, so using the dates from Table1 I need to bring from Table 2 all the data with D-1, at the exemple data, Date E column begins with 02/03/2024 then 05/03/2024 and so on, I need to bring from table2 all the values among the dates 02/03 - 04/03, then 05/03 - 06/03 and 07/03 - 10/03. This takes us for the next condition
*This information must be a mean(), so there are 5 rows from 02/03 in table1. So, we must sum all the values from column value() among the dates 02/03 - 04/03 and them divide them among all the rows with the date 02/03 in equal values (thats the motive I said it's a mean() ) and then the same logic for the others dates.
This would be the output:
data = {'DATA EMBARQUE': ['02/03/2024', '02/03/2024', '02/03/2024', '02/03/2024', '02/03/2024','05/03/2024', '05/03/2024', '05/03/2024', '05/03/2024', '07/03/2024','11/03/2024', '11/03/2024', '05/03/2024', '05/03/2024', '05/03/2024','07/03/2024', '11/03/2024', '11/03/2024' ],'PLACA': ['DPB0329', 'DPB0329', 'DPB0329', 'DPB0329', 'DPB0329','DPB0329', 'DPB0329', 'DPB0329', 'DPB0329', 'DPB0329','DPB0329', 'DPB0329', 'DPB0311', 'DPB0311', 'DPB0311','DPB0311', 'DPB0311', 'DPB0311' ],'Valor': [ 407.75, 407.75, 407.75, 407.75, 407.75, 216.45, 216.45, 216.45, 216.45, 1884.87, 253.00, 253.00, 288.60, 288.60, 288.60, 1884.87, 253.00, 253.00 ]}
How can I do this in Python?