|
import pandas as pd |
|
import os |
|
|
|
def generate_markdown_manifest_for_all_csvs(): |
|
|
|
current_dir = os.getcwd() |
|
|
|
|
|
output_folder = os.path.join(current_dir, 'params') |
|
if not os.path.exists(output_folder): |
|
os.makedirs(output_folder) |
|
|
|
|
|
csv_files = [f for f in os.listdir(current_dir) if f.endswith('.csv')] |
|
|
|
if not csv_files: |
|
print("No CSV files found in the current directory.") |
|
return |
|
|
|
|
|
for csv_file in csv_files: |
|
try: |
|
|
|
csv_path = os.path.join(current_dir, csv_file) |
|
df = pd.read_csv(csv_path) |
|
|
|
|
|
markdown_content = f"# Manifest for {csv_file}\n\n" |
|
markdown_content += f"## Column Overview\n\n" |
|
|
|
for col in df.columns: |
|
|
|
if col == "Value": |
|
continue |
|
|
|
unique_values = df[col].dropna().unique() |
|
markdown_content += f"### {col}\n\n" |
|
markdown_content += "Parameters:\n\n" |
|
for val in unique_values: |
|
markdown_content += f"- {val}\n" |
|
markdown_content += "\n" |
|
|
|
|
|
output_file = os.path.join(output_folder, f"{os.path.splitext(csv_file)[0]}_manifest.md") |
|
|
|
|
|
with open(output_file, 'w') as f: |
|
f.write(markdown_content) |
|
|
|
print(f"Manifest for {csv_file} saved to {output_file}") |
|
|
|
except Exception as e: |
|
print(f"Error processing {csv_file}: {e}") |
|
|
|
|
|
generate_markdown_manifest_for_all_csvs() |
|
|