|
4 | 4 | def repair_dropped_frames(df: pd.DataFrame) -> pd.DataFrame:
|
5 | 5 | pass
|
6 | 6 |
|
7 |
| - |
| 7 | +# Function to find the largest value in the first entry of all dataframes |
| 8 | +def find_largest_first_entry(dfs): |
| 9 | + largest_value = float('-inf') |
| 10 | + for df in dfs: |
| 11 | + first_entry = df.iloc[0, 0] |
| 12 | + if first_entry > largest_value: |
| 13 | + largest_value = first_entry |
| 14 | + return largest_value |
| 15 | + |
| 16 | +# Function to find the smallest value in the last entry of selected dataframes |
| 17 | +def find_smallest_last_entry(dfs): |
| 18 | + smallest_value = float('inf') |
| 19 | + for df in dfs: |
| 20 | + last_entry = df.iloc[-1, 0] |
| 21 | + if last_entry < smallest_value: |
| 22 | + smallest_value = last_entry |
| 23 | + return smallest_value |
| 24 | + |
| 25 | +# Function to find the largest & smallest value in the first and last entry of dataframes |
8 | 26 | def compute_time_range(dfs):
|
9 | 27 | # Find the lowest and highest numbers in all the data frames
|
10 |
| - min_common = max(df.iloc[:,0].min() for df in dfs) |
11 |
| - max_common = min(df.iloc[:,0].max() for df in dfs) |
12 |
| - |
13 |
| - # Print the results |
14 |
| - print(f"The lowest common number is {min_common}") |
15 |
| - print(f"The highest common number is {max_common}") |
16 |
| - |
17 |
| - return (min_common, max_common) |
18 |
| - |
19 |
| - |
20 |
| -def trim_into_interval(csv_path, dfs, min_common, max_common): |
21 |
| - # Trim each data frame to the min_common and max_common interval and save to a new file |
22 |
| - for i, df in enumerate(dfs): |
23 |
| - df_trimmed = df[(df.iloc[:,0] >= min_common) & (df.iloc[:,0] <= max_common)] |
24 |
| - df_trimmed.to_csv(f"{csv_path}trimmed_df_{i+1}.csv", header=False, index=False) |
25 |
| - |
26 |
| - # Print the results |
27 |
| - print(f"{len(dfs)} data frames trimmed and saved to {csv_path}") |
| 28 | + lower_value = find_largest_first_entry(dfs) |
| 29 | + higher_value = find_smallest_last_entry(dfs) |
| 30 | + |
| 31 | + # return the results |
| 32 | + return (lower_value, higher_value) |
| 33 | + |
| 34 | +# Function to trim dataframes based on specified values |
| 35 | +def trim_into_interval(dfs, min_common, max_common, threshold): |
| 36 | + trimmed_dataframes = [] |
| 37 | + # import pdb;pdb.set_trace() |
| 38 | + 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)] |
| 41 | + trimmed_df = df[(df.iloc[:, 0] >= start.iloc[0, 0]) & (df.iloc[:, 0] <= end.iloc[0, 0])].reset_index(drop=True) |
| 42 | + trimmed_dataframes.append(trimmed_df) |
| 43 | + return trimmed_dataframes |
0 commit comments