import pandas as pd
import os
def export_string_results(results, output_dir="output", dry_run=True):
"""
Exports string results to a CSV file for exploratory analysis.
Args:
results (dict): A dictionary where keys are labels and values are lists of strings.
output_dir (str): The directory to save the CSV file. Defaults to "output".
dry_run (bool): If True, only prints the file path without creating the file. Defaults to True.
"""
if not os.path.exists(output_dir):
os.makedirs(output_dir)
filename = os.path.join(output_dir, "string_results.csv")
if dry_run:
print(f"Dry run: Would export to {filename}")
else:
df = pd.DataFrame(results)
df.to_csv(filename, index=False)
print(f"Exported to {filename}")
if __name__ == '__main__':
# Example usage
example_results = {
"label_a": ["apple", "banana", "cherry"],
"label_b": ["red", "green", "blue"],
"label_c": ["one", "two", "three"]
}
export_string_results(example_results, output_dir="my_results", dry_run=True)
export_string_results(example_results, output_dir="my_results", dry_run=False)
Add your comment