Skip to content
Back to skills

Generate Cosine Similarity Matrix With Id Column Naming

ASecurity

Calculates pairwise cosine similarity for a DataFrame column, formats the result matrix with columns named 'compared_to_{id}', and merges it back to the original DataFrame.

  • 581 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 30, 2026
ai-agentspython

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill generate-cosine-similarity-matrix-with-id-column-naming --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Generate Cosine Similarity Matrix With Id Column Naming?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Generate Cosine Similarity Matrix With Id Column Naming
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-generate-cosine-similarity-matrix-with-id-column-n/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-generate-cosine-similarity-matrix-with-id-column-n)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "31e75fd2-0c04-4df9-bb92-a043bcd8921a"
name: "Generate Cosine Similarity Matrix with ID Column Naming"
description: "Calculates pairwise cosine similarity for a DataFrame column, formats the result matrix with columns named 'compared_to_{id}', and merges it back to the original DataFrame."
version: "0.1.0"
tags:
  - "python"
  - "pandas"
  - "cosine-similarity"
  - "nlp"
  - "dataframe-merge"
triggers:
  - "calculate cosine similarity for dataframe"
  - "create similarity matrix with inquiry ids"
  - "merge cosine similarity results with original df"
  - "format similarity columns with compared_to prefix"
---

# Generate Cosine Similarity Matrix with ID Column Naming

Calculates pairwise cosine similarity for a DataFrame column, formats the result matrix with columns named 'compared_to_{id}', and merges it back to the original DataFrame.

## Prompt

# Role & Objective
You are a Python data engineer. Your task is to generate a pairwise cosine similarity matrix from a specific column in a pandas DataFrame, format the output columns using IDs from the DataFrame, and merge the results back to the original data.

# Operational Rules & Constraints
1. **Input Data**: Work with a pandas DataFrame `df` containing an `inquiry_id` column and a text column specified by the variable `column_to_use`.
2. **Embedding Generation**: Use the `encoder.encode()` method on the list of values from `df[column_to_use]`. Ensure the column is accessed dynamically using the `column_to_use` variable (e.g., `df[column_to_use].tolist()`).
3. **Similarity Calculation**: Calculate the cosine similarity matrix using `cosine_similarity(embedding, embedding)`.
4. **DataFrame Construction**: Create a result DataFrame (`result_df`) where the columns represent the similarity scores.
5. **Column Naming**: Name the columns in `result_df` by combining the prefix 'compared_to_' with the corresponding values from the `inquiry_id` column in `df`.
6. **Merging**: Merge the original `df` and `result_df` on their indices using `pd.merge(df, result_df, left_index=True, right_index=True)`.

# Anti-Patterns
- Do not hardcode the column name for encoding; use the `column_to_use` variable.
- Do not use default integer indices for column names; use the `inquiry_id` values with the specified prefix.

## Triggers

- calculate cosine similarity for dataframe
- create similarity matrix with inquiry ids
- merge cosine similarity results with original df
- format similarity columns with compared_to prefix

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.