In [1]:

    import pandas as pd
    import numpy as np

In [2]:

    df = pd.read_csv("ZebraBotswana.txt")

In [3]:

    print(df.shape)

    (53776, 4)

The dataset contains 53776 records, with 4 columns.

In [4]:

    print(df.columns)

    Index(['UnixTime', 'Lng', 'Lat', 'Animal'], dtype='object')

In [5]:

    print(df.head())

           UnixTime        Lng        Lat Animal
    0  1.193263e+09  23.523616 -19.391531  Z3864
    1  1.193267e+09  23.523497 -19.391684  Z3864
    2  1.193270e+09  23.523463 -19.391651  Z3864
    3  1.193274e+09  23.523425 -19.391645  Z3864
    4  1.193278e+09  23.523434 -19.391541  Z3864

In [6]:

    animals = np.unique(df["Animal"])
    print(animals)

    ['Z3743' 'Z3864' 'Z3866' 'Z6399' 'Z6402' 'Z6405' 'Z6407']

We calculate the day (integer) corresponding to each Unix timestamp by dividing the Unix timestamp by 24 times 60 times 60.

In [7]:

    df["day"] = df["UnixTime"].map(lambda x: int(x/(24.*60.*60.)))
    print(df.head())

           UnixTime        Lng        Lat Animal    day
    0  1.193263e+09  23.523616 -19.391531  Z3864  13810
    1  1.193267e+09  23.523497 -19.391684  Z3864  13810
    2  1.193270e+09  23.523463 -19.391651  Z3864  13811
    3  1.193274e+09  23.523425 -19.391645  Z3864  13811
    4  1.193278e+09  23.523434 -19.391541  Z3864  13811

In [8]:

    lat_to_dist = 111.3 # distance in km of a degree in longitude
    lng_to_dist = 104.6 # distance in km of a degree in latitude

In [9]:

    for animal in animals:
        df_animal = df[df["Animal"]==animal].copy()
        lng = np.array(df_animal["Lng"])
        lat = np.array(df_animal["Lat"])
        dlng = (lng[1:]-lng[:-1])*lng_to_dist
        dlat = (lat[1:]-lat[:-1])*lat_to_dist
        dist = (dlng**2+dlat**2)**0.5
        df_animal["dist"] = np.hstack([0,dist]) # Adding the missing element due to distancing
        daily_distance = df_animal.groupby(["day"]).sum()["dist"]
        print(animal)
        print("Avg. daily distance:    %5.2f+/-%5.2f km"%(daily_distance.mean(),daily_distance.std()))
        print("Min/Max daily distance: %5.2f km / %5.2f km"%(daily_distance.min(),daily_distance.max()))

    Z3743
    Avg. daily distance:    12.23+/- 9.03 km
    Min/Max daily distance:  0.24 km / 57.76 km
    Z3864
    Avg. daily distance:    15.50+/-11.22 km
    Min/Max daily distance:  0.02 km / 52.74 km
    Z3866
    Avg. daily distance:    11.25+/- 6.76 km
    Min/Max daily distance:  2.51 km / 56.76 km
    Z6399
    Avg. daily distance:    13.78+/- 9.10 km
    Min/Max daily distance:  1.22 km / 75.40 km
    Z6402
    Avg. daily distance:    12.38+/- 7.20 km
    Min/Max daily distance:  0.38 km / 51.02 km
    Z6405
    Avg. daily distance:    11.68+/- 7.04 km
    Min/Max daily distance:  2.53 km / 53.59 km
    Z6407
    Avg. daily distance:    12.45+/- 7.15 km
    Min/Max daily distance:  0.17 km / 51.31 km

In [ ]: