| import pandas as pd
|
|
|
|
|
| file_names = ['7_layer_output.csv']
|
| output_file = '8_layer_output.csv'
|
|
|
|
|
| extracted_data = []
|
|
|
| for file in file_names:
|
| try:
|
|
|
|
|
| df = pd.read_csv(file, usecols=lambda x: 'rolling' in x)
|
|
|
|
|
|
|
| prefix = file.replace('.csv', '') + '_'
|
| df = df.add_prefix(prefix)
|
|
|
| extracted_data.append(df)
|
| print(f"Processed {file}: Extracted {df.shape[1]} columns.")
|
|
|
| except FileNotFoundError:
|
| print(f"Error: The file '{file}' was not found.")
|
| except Exception as e:
|
| print(f"An error occurred while reading '{file}': {e}")
|
|
|
|
|
| if extracted_data:
|
|
|
|
|
| combined_df = pd.concat(extracted_data, axis=1)
|
|
|
|
|
| combined_df.to_csv(output_file, index=False)
|
| print(f"\nSuccess! Combined data saved to '{output_file}'")
|
| else:
|
| print("\nNo columns were extracted.") |