Skip to content

Commit 97ea371

Browse files
Saurabh PandeySaurabh Pandey
authored andcommitted
dataframe trim done
1 parent 7e6518f commit 97ea371

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

PostProcessing/dataframes.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
def repair_dropped_frames(df: pd.DataFrame) -> pd.DataFrame:
66
pass
77

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+
818

919
# Function to find the largest value in the first entry of all dataframes
1020
def find_largest_first_entry(dfs):
@@ -39,10 +49,14 @@ def compute_time_range(dfs) -> Tuple[int, int]:
3949
# Function to trim dataframes based on specified values
4050
def trim_into_interval(dfs, min_common, max_common, threshold):
4151
trimmed_dataframes = []
42-
# import pdb;pdb.set_trace()
4352
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.")
4862
return trimmed_dataframes

0 commit comments

Comments
 (0)