Replace several coordinates by its mean value grouped by multiindex Pandas

by Digd   Last Updated August 09, 2018 12:22 PM

I have a table with some info that are getting by a GPS, in my table I have this structure:

        Date    Time    Latitude    Longitude   Accuracy    Weather Visibility  ViewPoint   Species Bearing Distance    Count
29/12/2018  10:20:45    39.85528    -5.36466    1.500000001 Soleado Buena   Otero 4 Anser anser 210 600 70
29/12/2018  10:23:32    39.85528    -5.36466    1.500000001 Soleado Buena   Otero 4 Anser anser 260 900 20
29/12/2018  10:24:17    39.85528    -5.36466    1.500000001 Soleado Buena   Otero 4 Larus fuscus    230 500 2
29/12/2018  10:05:16    39.85528    -5.36466    1.299999952 Soleado Buena   Otero 4 Fulica atra 100 450 60
29/12/2018  10:09:47    39.85528    -5.36466    1.299999952 Soleado Buena   Otero 4 Anser anser 160 560 110
29/12/2018  10:12:41    39.85528    -5.36466    1.299999952 Soleado Buena   Otero 4 Anas penelope   160 560 200
29/12/2018  10:17:33    39.85528    -5.36466    1.299999952 Soleado Buena   Otero 4 Anser anser 194 560 45
29/12/2018  10:20:01    39.85528    -5.36466    1.299999952 Soleado Buena   Otero 4 Anser anser 200 560 60
29/12/2018  08:50:07    39.86689    -5.35504    2.000000001 Soleado Buena   Otero 5 Anser anser 0   0   
29/12/2018  08:55:49    39.866885   -5.355045   1.500000001 Soleado Buena   Otero 5 Anas penelope   200 550 60

I need to get the mean coordinates (to improve the GPS error) by the ViewPoint and Date. So, for the Date 1, I am going to have a mean coordinate for the ViewPoint1 (Otero1), and other mean coordinates for every ViewPoint. Later on, in the next Date, I am going to have the same structure, but the ViewPoint can be slightly displaced from one date to another, that's why I need group also by Date and not on ly by the ViewPoint.

I can apply the groupby and I get almost what I need:

df.groupby(['Date', 'ViewPoint'], as_index=True)['Latitude', 'Longitude'].mean()

Which throws this output:

                       Latitude Longitude
Date        ViewPoint
2016-12-29  Otero 0 39.859567   -5.399055
            Otero 1 39.871807   -5.385762
            Otero 3 39.853757   -5.381488
            Otero 4 39.855280   -5.364660
            Otero 5 39.866887   -5.354937
            Otero 9 39.830826   -5.356414
            OteroX  39.854657   -5.391452
2017-01-10  Otero 0 39.858376   -5.395767
            Otero 1 39.871402   -5.385639
            Otero 2 39.874892   -5.379403
            Otero 4 39.855324   -5.364828
            Otero 5 39.866883   -5.355035
            Otero 9 39.830876   -5.356457

So, what I am missing is how to replace the mean values in every row of the original table, with its mean values in the same combination "Date" and "ViewPoint"



Related Questions


Updated June 19, 2018 08:22 AM

Updated June 14, 2018 06:22 AM

Updated October 20, 2017 10:22 AM

Updated August 05, 2018 15:22 PM

Updated August 28, 2017 12:22 PM