I have this dataframe, consisting in 73 rows:
Date Col1 Col2 Col3
1975 float float float
1976 float float float
1976 float float float
1977 float float float
1978 float float float
....
....
There are certain years appearing twice because the values were taken twice that year. What I want to do is to merge those rows where the year is the same, taking the mean value of each column for those specific two rows. The fact is that I am still familiarizing with pandas and I don't really understand the usage of the loc and iloc selectors. This is what I have tried, but I am sure this is completely wrong and non-pythonic:
for i in range(72):
if df.Date[i]==df.Date[i+1]:
df.Very_satisfied[i]= (df.Very_satisfied[i]+df.Very_satisfied[i+1])/2
df.Fairly_satisfied[i]= (df.Fairly_satisfied[i]+df.Fairly_satisfied[i+1])/2
df.NV_satisfied[i]= (df.NV_satisfied[i]+ df.NV_satisfied[i+1])/2
df.Not_satisfied[i]= (df.Not_satisfied[i]+ df.Not_satisfied[i+1])/2
df.DK[i]= (df.DK[i]+ df.DK[i+1])/2
a=i+1
str(a)
df.drop(a)
where "very satisfied", "fairly satisfied" ecc. are the columns. The point in my code is: if two years are the same calculate the mean of each value, substitute it in the first row and delete the second row. I really need something smarter and more elegant.