|
import os |
|
import pandas as pd |
|
|
|
|
|
csv_directory = '/media/joe/512-3/csv' |
|
|
|
|
|
column_names = ['score', 'text', 'url'] |
|
|
|
|
|
def add_headers_to_csv(file_path): |
|
try: |
|
|
|
df = pd.read_csv(file_path, header=None) |
|
|
|
|
|
df.columns = column_names |
|
|
|
|
|
df.to_csv(file_path, index=False) |
|
|
|
print(f"Headers added to '{file_path}'") |
|
|
|
except Exception as e: |
|
print(f"Error processing '{file_path}': {e}") |
|
|
|
|
|
for file_name in os.listdir(csv_directory): |
|
if file_name.endswith('.csv'): |
|
file_path = os.path.join(csv_directory, file_name) |
|
add_headers_to_csv(file_path) |
|
|
|
print("All CSV files processed.") |
|
|
|
|