|
5 | 5 | def repair_dropped_frames(df: pd.DataFrame) -> pd.DataFrame:
|
6 | 6 | pass
|
7 | 7 |
|
| 8 | +def save_dataframes(dataframes, prefix='df'): |
| 9 | + # Generate filenames based on a pattern or numbering scheme |
| 10 | + filenames = [f"{prefix}{i}.csv" for i in range(1, len(dataframes) + 1)] |
| 11 | + |
| 12 | + # Save each DataFrame to a separate file |
| 13 | + for i, df in enumerate(dataframes): |
| 14 | + filename = filenames[i] |
| 15 | + df.to_csv(filename, index=False, header=False) |
| 16 | + print("DataFrames saved successfully.") |
| 17 | + |
8 | 18 |
|
9 | 19 | # Function to find the largest value in the first entry of all dataframes
|
10 | 20 | def find_largest_first_entry(dfs):
|
@@ -39,10 +49,14 @@ def compute_time_range(dfs) -> Tuple[int, int]:
|
39 | 49 | # Function to trim dataframes based on specified values
|
40 | 50 | def trim_into_interval(dfs, min_common, max_common, threshold):
|
41 | 51 | trimmed_dataframes = []
|
42 |
| - # import pdb;pdb.set_trace() |
43 | 52 | for df in dfs:
|
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)] |
46 |
| - trimmed_df = df[(df.iloc[:, 0] >= start.iloc[0, 0]) & (df.iloc[:, 0] <= end.iloc[0, 0])].reset_index(drop=True) |
47 |
| - trimmed_dataframes.append(trimmed_df) |
| 53 | + start: pd.DataFrame = df[df.iloc[:, 0].between(min_common-threshold, min_common+threshold, inclusive='both')] |
| 54 | + end: pd.DataFrame = df[df.iloc[:, 0].between(max_common-threshold, max_common+threshold, inclusive='both')] |
| 55 | + if not start.empty and not end.empty : |
| 56 | + df_start = start.stack().iloc[0] |
| 57 | + df_end = end.stack().iloc[-1] |
| 58 | + trimmed_df = df[df.iloc[:, 0].between(df_start, df_end, inclusive='both')] |
| 59 | + trimmed_dataframes.append(trimmed_df) |
| 60 | + else: |
| 61 | + print("No values found within the specified range.") |
48 | 62 | return trimmed_dataframes
|
0 commit comments