I have the following data set:

  Country  Product   Price  Year_Month
     AE         1           20    201204
     DE         1           20    201204
     CN         1           28    201204
     AE         2           28    201204
     DE         2           28    201204
     CN         2           22    201204
     AE         3           28    201204
     CN         3           28    201204
     AE         1           20    201205
     DE         1           20    201205
     CN         1           28    201205
     AE         2           28    201205
     DE         2           28    201205

I want to create the one more column which is "The average price of the
product in other areas".
in other word, for each month, for each product, I calculate the average of
such product in the other area.

I want sth like:

  Country  Product   Price  Year_Month    Price_average_In_Other_area
     AE         1           20    201204              14
     AE         2           28    201204              25

Please avoid the three for loop, I have tried and it never end. I have
 1070427 rows.  Is there better way to speed up my program?

	[[alternative HTML version deleted]]

