chat1
import csv
import itertools
import pandas as pd
def generate_combinations(input_file, output_file):
# Load the CSV file into a pandas DataFrame
df = pd.read_csv(input_file)
# Replace NaN with an empty string to treat empty cells as valid entries
df = df.fillna('')
# Generate all possible row combinations by creating a list of listsunique withvalues (including empty strings) for each column's unique valuescolumn
columns_data = [df[col].unique() for col in df.columns]
# Use itertools.product to get all possible combinations of values across columns
combinations = list(itertools.product(*columns_data))
# Create a new DataFrame from the combinations and write to CSV
output_df = pd.DataFrame(combinations, columns=df.columns)
output_df.to_csv(output_file, index=False)
print(f"Combinations have been saved to {output_file}")
# Usage example:
generate_combinations('input.csv', 'output.csv')