I have one dataframe as below. I want to groupby this dataframe by two conditions (column 'date' and column 'price') and add one column to calculate the mean of "price2"(which has the same date and price). Thanks.
import pandas as pd
import numpy as np
df2 = pd.DataFrame({
'date': [20130101,20130101, 20130105, 20130105, 20130101, 20130108],
'price': [25, 25, 23.5, 27, 40, 8],
'price2':[23,56,45,67,33,2]
})
date output price price2
0 20130101 39.5 25.0 23
1 20130101 39.5 25.0 56
2 20130105 45.0 23.5 45
3 20130105 67.0 27.0 67
4 20130101 33.0 40.0 33
5 20130108 2.0 8.0 2