import pandas as pd | |
import numpy as np | |
def find_similar(p_index, similarity_matrix, filtered_df, top_x): | |
# filter out just projects from filtered df | |
filtered_indices = filtered_df.index.tolist() | |
index_position_mapping = {position: index for position, index in enumerate(filtered_indices)} | |
filtered_column_sim_matrix = similarity_matrix[:, filtered_indices] | |
# filter out the row of the selected poject | |
project_row = filtered_column_sim_matrix[p_index] | |
sorted_indices = np.argsort(project_row) | |
top_10_indices_descending = sorted_indices[-10:][::-1] | |
#top_10_original_indices = [index_position_mapping[position] for position in top_10_indices_descending] | |
top_10_values_descending = project_row[top_10_indices_descending] | |
result_df = filtered_df.iloc[top_10_indices_descending] | |
result_df["similarity"] = top_10_values_descending | |
return result_df | |