import pandas as pd import glob import os # --------------------------------------------------------- # STEP 1 - Ask user which spring to process # --------------------------------------------------------- spring_name = input("Enter spring number (example: 1040_01): ").strip() # --------------------------------------------------------- # STEP 2 - Find all matching test files # --------------------------------------------------------- file_pattern = f"Spring_{spring_name}_Test_*.csv" file_list = glob.glob(file_pattern) # Make sure files are processed in order file_list.sort() if len(file_list) == 0: print(f"No files found matching: {file_pattern}") exit() # --------------------------------------------------------- # STEP 3 - Variables used while combining files # --------------------------------------------------------- combined_data = [] time_offset = 0 # --------------------------------------------------------- # STEP 4 - Process each test file # --------------------------------------------------------- for test_number, file in enumerate(file_list, start=1): print(f"Processing: {file}") # Read CSV df = pd.read_csv(file) # Remove rows containing empty data df = df.dropna() # Time column name time_column = "Time (s)" # Create Test column df["Test"] = test_number # Create continuous time column df["Continuous Time (s)"] = df[time_column] + time_offset # Determine ending time for next test last_time = df[time_column].iloc[-1] time_offset += last_time # Store cleaned data combined_data.append(df) # --------------------------------------------------------- # STEP 5 - Combine all tests into one dataframe # --------------------------------------------------------- final_df = pd.concat(combined_data, ignore_index=True) # --------------------------------------------------------- # STEP 6 - Create output filename # --------------------------------------------------------- output_file = f"Spring_{spring_name}_Cleaned.csv" # --------------------------------------------------------- # STEP 7 - Save cleaned data # --------------------------------------------------------- final_df.to_csv(output_file, index=False) print() print(f"Finished!") print(f"Output saved as: {output_file}")