File size: 1,045 Bytes
ca165c7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import pandas as pd
# Read word_scores2.csv
word_scores = pd.read_csv('word_scores2.csv')
# Read matrix5.csv
matrix5 = pd.read_csv('matrix5.csv', header=None)
# Initialize an empty matrix
output_matrix = []
# Initialize a variable to keep track of the position in matrix5
matrix_position = 0
# 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 matrix5.csv and update position
elif score == 1:
output_matrix.append(matrix5.iloc[matrix_position % len(matrix5)].tolist())
matrix_position += 1
# 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('loopnumber.csv', header=False, index=False)
|