import pandas as pd # Read word_scores2.csv word_scores = pd.read_csv('word_scores2.csv') # Read matrix2.csv matrix2 = pd.read_csv('matrix5.csv', header=None) # Initialize an empty matrix output_matrix = [] # Iterate through each row in word_scores for index, row in word_scores.iterrows(): score = row['Score'] # If the score is 0, add a row of zeros to the output matrix if score == 0: output_matrix.append([0] * 6) # If the score is 1, use the corresponding row from matrix2.csv elif score == 1: output_matrix.append(matrix2.iloc[index % len(matrix2)].tolist()) # Convert the output_matrix to a DataFrame result_output_matrix = pd.DataFrame(output_matrix, columns=['Col1', 'Col2', 'Col3', 'Col4', 'Col5', 'Col6']) # Save the result_output_matrix to a CSV file without a header result_output_matrix.to_csv('loopnum.csv', header=False, index=False)