1
1
import pandas as pd
2
2
3
+ from typing import Tuple
3
4
4
5
def repair_dropped_frames (df : pd .DataFrame ) -> pd .DataFrame :
5
6
pass
6
7
8
+
7
9
# Function to find the largest value in the first entry of all dataframes
8
10
def find_largest_first_entry (dfs ):
9
11
largest_value = float ('-inf' )
@@ -13,6 +15,7 @@ def find_largest_first_entry(dfs):
13
15
largest_value = first_entry
14
16
return largest_value
15
17
18
+
16
19
# Function to find the smallest value in the last entry of selected dataframes
17
20
def find_smallest_last_entry (dfs ):
18
21
smallest_value = float ('inf' )
@@ -22,22 +25,24 @@ def find_smallest_last_entry(dfs):
22
25
smallest_value = last_entry
23
26
return smallest_value
24
27
28
+
25
29
# Function to find the largest & smallest value in the first and last entry of dataframes
26
- def compute_time_range (dfs ):
30
+ def compute_time_range (dfs ) -> Tuple [ int , int ] :
27
31
# Find the lowest and highest numbers in all the data frames
28
32
lower_value = find_largest_first_entry (dfs )
29
33
higher_value = find_smallest_last_entry (dfs )
30
34
31
35
# return the results
32
- return (lower_value , higher_value )
36
+ return lower_value , higher_value
37
+
33
38
34
39
# Function to trim dataframes based on specified values
35
40
def trim_into_interval (dfs , min_common , max_common , threshold ):
36
41
trimmed_dataframes = []
37
42
# import pdb;pdb.set_trace()
38
43
for df in dfs :
39
- start = df [(df .iloc [:, 0 ] >= min_common - threshold ) & (df .iloc [:, 0 ] <= min_common + threshold )]
40
- end = df [(df .iloc [:, 0 ] >= max_common - threshold ) & (df .iloc [:, 0 ] <= max_common + threshold )]
44
+ start : pd . DataFrame = df [(df .iloc [:, 0 ] >= min_common - threshold ) & (df .iloc [:, 0 ] <= min_common + threshold )]
45
+ end : pd . DataFrame = df [(df .iloc [:, 0 ] >= max_common - threshold ) & (df .iloc [:, 0 ] <= max_common + threshold )]
41
46
trimmed_df = df [(df .iloc [:, 0 ] >= start .iloc [0 , 0 ]) & (df .iloc [:, 0 ] <= end .iloc [0 , 0 ])].reset_index (drop = True )
42
47
trimmed_dataframes .append (trimmed_df )
43
48
return trimmed_dataframes
0 commit comments