@@ -91,8 +91,6 @@ def str_to_datetime(dt_str: Text) -> datetime:
9191
9292 Example
9393 -------
94- from datetime import datetime
95-
9694 time_1 = '2020-06-29'
9795 time_2 = '2020-06-29 12:45:59'
9896
@@ -193,8 +191,6 @@ def min_to_datetime(minutes: int) -> datetime:
193191
194192 Example
195193 -------
196- from datetime import datetime
197-
198194 print(min_to_datetime(26996497), type(min_to_datetime(26996497)))
199195 >>> 2021-04-30 13:37:00 <class 'datetime.datetime'>
200196
@@ -218,7 +214,6 @@ def to_day_of_week_int(dt: datetime) -> int:
218214
219215 Example
220216 -------
221- import datetime
222217 from pymove.utils.datetime import str_to_datetime
223218
224219 monday = str_to_datetime('2021-05-3 12:00:01')
@@ -258,10 +253,7 @@ def working_day(
258253
259254 Examples
260255 --------
261- from datetime import datetime
262- from typing import Optional, Text, Union
263256 from pymove.utils.datetime import str_to_datetime
264- import holidays
265257
266258 independence_day = str_to_datetime('2021-09-7 12:00:01')
267259 # In Brazil this day is a holiday
@@ -596,26 +588,19 @@ def generate_time_statistics(
596588
597589 Example
598590 -------
599- from typing import Optional, Text
600- from pymove.utils.constants import (COUNT, LOCAL_LABEL, MAX, MEAN, MIN,
601- PREV_LOCAL, STD, SUM, TIME_TO_PREV,)
602-
603- >>> df
604- local_label prev_local time_to_prev
605- 0 261 NaN NaN
606- 1 580 261.0 252.0
607- 2 376 580.0 91.0
608- 3 386 376.0 17449.0
609- 4 644 386.0 21824.0
610-
611- >>> generate_time_statistics(df)
612- local_label prev_local mean std min max sum count
613- 0 376 580.0 91.0 0.0 91.0 91.0 91.0 1
614- 1 386 376.0 17449.0 0.0 17449.0 17449.0 17449.0 1
615- 2 580 261.0 252.0 0.0 252.0 252.0 252.0 1
616- 3 644 386.0 21824.0 0.0 21824.0 21824.0 21824.0 1
617-
618-
591+ df
592+ >>> local_label prev_local time_to_prev id
593+ 0 house None NaN 1
594+ 1 market house 720.0 1
595+ 2 market market 5.0 1
596+ 3 market market 1.0 1
597+ 4 school market 844.0 1
598+
599+ generate_time_statistics(df)
600+ >>> local_label prev_local mean std min max sum count
601+ 0 house market 844.0 0.000000 844.0 844.0 844.0 1
602+ 1 market house 720.0 0.000000 720.0 720.0 720.0 1
603+ 2 market market 3.0 2.828427 1.0 5.0 6.0 2
619604 """
620605 df_statistics = data .groupby (
621606 [local_label , PREV_LOCAL ]
@@ -695,42 +680,33 @@ def threshold_time_statistics(
695680
696681 Example
697682 -------
698- from pandas import DataFrame
699- from typing import Optional, Text
700683 from pymove.utils.datetime import generate_time_statistics, _calc_time_threshold
701- from pymove.utils.constants import (COUNT, LOCAL_LABEL, MAX, MEAN, MIN,
702- PREV_LOCAL, STD, SUM, TIME_TO_PREV,THRESHOLD)
703-
704- >>> df
705- local_label prev_local time_to_prev
706- 0 261 NaN NaN
707- 1 580 261.0 252.0
708- 2 376 580.0 91.0
709- 3 386 376.0 17449.0
710- 4 644 386.0 21824.0
711-
712- >>> statistics = generate_time_statistics(df)
713- statistics
714- local_label prev_local mean std min max sum count
715- 0 376 580.0 91.0 0.0 91.0 91.0 91.0 1
716- 1 386 376.0 17449.0 0.0 17449.0 17449.0 17449.0 1
717- 2 580 261.0 252.0 0.0 252.0 252.0 252.0 1
718- 3 644 386.0 21824.0 0.0 21824.0 21824.0 21824.0 1
719684
685+ df
686+ >>> local_label prev_local time_to_prev id
687+ 0 house None NaN 1
688+ 1 market house 720.0 1
689+ 2 market market 5.0 1
690+ 3 market market 1.0 1
691+ 4 school market 844.0 1
720692
721- >>> threshold_time_statistics(statistics)
693+ statistics = generate_time_statistics(df)
694+ statistics
695+ >>> local_label prev_local mean std min max sum count
696+ 0 house market 844.0 0.000000 844.0 844.0 844.0 1
697+ 1 market house 720.0 0.000000 720.0 720.0 720.0 1
698+ 2 market market 3.0 2.828427 1.0 5.0 6.0 2
722699
723- local_label prev_local mean std min max sum count
724- 0 376 580.0 91.0 0.0 91.0 91.0 91.0 1
725- 1 386 376.0 17449.0 0.0 17449.0 17449.0 17449.0 1
726- 2 580 261.0 252.0 0.0 252.0 252.0 252.0 1
727- 3 644 386.0 21824.0 0.0 21824.0 21824.0 21824.0 1
700+ threshold_time_statistics(statistics)
701+ >>> local_label prev_local mean std min max sum count
702+ 0 house market 844.0 0.000000 844.0 844.0 844.0 1
703+ 1 market house 720.0 0.000000 720.0 720.0 720.0 1
704+ 2 market market 3.0 2.828427 1.0 5.0 6.0 2
728705
729706 threshold
730- 0 91.0
731- 1 17449.0
732- 2 52.0
733- 3 21824.0
707+ 0 844.0
708+ 1 720.0
709+ 2 5.8
734710 """
735711 if not inplace :
736712 df_statistics = df_statistics .copy ()
0 commit comments