Untitled
unknown
plain_text
a month ago
833 B
2
Indexable
Never
import os import pandas as pd def combine_specific_csv_files(directory_path, output_file, keyword): # List to hold dataframes dataframes = [] # Iterate over all files in the directory for filename in os.listdir(directory_path): if filename.endswith(".csv") and keyword in filename: file_path = os.path.join(directory_path, filename) df = pd.read_csv(file_path) dataframes.append(df) # Combine all dataframes combined_df = pd.concat(dataframes, ignore_index=True) # Write the combined dataframe to a new CSV file combined_df.to_csv(output_file, index=False) # Example usage directory_path = 'path/to/your/csv/files' output_file = 'path/to/output/combined.csv' keyword = 'xxx' combine_specific_csv_files(directory_path, output_file, keyword)
Leave a Comment