# Run2 Stock Data Wrangling

> Robust data cleaning and formatting for financial datasets in D3.js.

- Skill: `cxcscmu/run2-stock-data-wrangling` (Agent Skill)
- Install (CLI): `npx get-skill add cxcscmu/run2-stock-data-wrangling`
- Raw SKILL.md: https://api.skillmd.com/api/skills/cxcscmu/run2-stock-data-wrangling/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: cxcscmu (https://skillmd.com/u/cxcscmu)
- Updated: 2026-11-24
- Page: https://skillmd.com/skills/cxcscmu/run2-stock-data-wrangling

---


# Stock Data Wrangling

Ensuring data consistency between individual files and the summary CSV.

## Robust ETF Detection

ETFs often have missing `sector` and `marketCap`. Explicitly label them to apply specific logic (uniform sizing, no tooltip).

```javascript
const processed = rawData.map(d => {
    const marketCap = d.marketCap ? parseFloat(d.marketCap) : null;
    const isETF = isNaN(marketCap) || !marketCap || d.sector === "" || d.sector === "ETF";
    return {
        ...d,
        marketCap,
        isETF,
        sector: isETF ? "ETF" : d.sector
    };
});
```

## Precise Market Cap Formatting

Formatting numbers to "1.64T" or "150B" using fixed precision.

```javascript
function formatCurrency(val) {
    if (!val) return "N/A";
    const trillion = 1e12;
    const billion = 1e9;
    const million = 1e6;
    
    if (val >= trillion) return (val / trillion).toFixed(2) + "T";
    if (val >= billion) return (val / billion).toFixed(2) + "B";
    if (val >= million) return (val / million).toFixed(2) + "M";
    return val.toLocaleString();
}
```

