<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>数据分析 on 进击的骑士</title>
    <link>https://knight134.com/tags/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/</link>
    <description>Recent content in 数据分析 on 进击的骑士</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Fri, 17 May 2024 16:00:00 +0800</lastBuildDate>
    <atom:link href="https://knight134.com/tags/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>SQL 查询优化：EXPLAIN 命令的妙用</title>
      <link>https://knight134.com/posts/2024-05-17-sql-optimization/</link>
      <pubDate>Fri, 17 May 2024 16:00:00 +0800</pubDate>
      <guid>https://knight134.com/posts/2024-05-17-sql-optimization/</guid>
      <description>&lt;p&gt;当数据量达到百万级时，一条慢查询足以拖垮整个服务。学会使用 &lt;code&gt;EXPLAIN&lt;/code&gt; 来分析 SQL 执行计划是必备技能。
主要关注 &lt;code&gt;type&lt;/code&gt; 列，如果是 &lt;code&gt;ALL&lt;/code&gt; 表示全表扫描，需要优化索引。&lt;/p&gt;</description>
    </item>
    <item>
      <title>使用 Pandas 进行数据清洗实战</title>
      <link>https://knight134.com/posts/2024-05-12-data-analysis-pandas/</link>
      <pubDate>Sun, 12 May 2024 10:30:00 +0800</pubDate>
      <guid>https://knight134.com/posts/2024-05-12-data-analysis-pandas/</guid>
      <description>&lt;p&gt;在数据分析的工作中，80% 的时间都在做数据清洗。今天记录一下使用 Pandas 处理缺失值和异常值的常用技巧。&lt;/p&gt;
&lt;h3 id=&#34;处理缺失值&#34;&gt;处理缺失值&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;dropna()&lt;/code&gt;：直接丢弃含有缺失值的行。&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fillna()&lt;/code&gt;：用均值、中位数或特定值填充。&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;数据透视表&#34;&gt;数据透视表&lt;/h3&gt;
&lt;p&gt;Pandas 的 &lt;code&gt;pivot_table&lt;/code&gt; 类似于 Excel 的数据透视表，非常强大。
python&lt;/p&gt;
&lt;p&gt;import pandas as pd&lt;/p&gt;
&lt;p&gt;df = pd.read_csv(&amp;lsquo;data.csv&amp;rsquo;)&lt;/p&gt;
&lt;p&gt;table = pd.pivot_table(df, values=&amp;lsquo;sales&amp;rsquo;, index=&amp;lsquo;region&amp;rsquo;, columns=&amp;lsquo;year&amp;rsquo;, aggfunc=&amp;lsquo;sum&amp;rsquo;)&lt;/p&gt;
&lt;p&gt;print(table)&lt;/p&gt;</description>
    </item>
    <item>
      <title>我的技术探索之旅：从数据分析到前端可视化</title>
      <link>https://knight134.com/posts/my-first-post/</link>
      <pubDate>Mon, 15 Jan 2024 10:00:00 +0800</pubDate>
      <guid>https://knight134.com/posts/my-first-post/</guid>
      <description>&lt;p&gt;这里是你的文章内容。你可以愉快地使用 &lt;strong&gt;Markdown&lt;/strong&gt; 语法。&lt;/p&gt;
&lt;h3 id=&#34;我的第一个数据可视化项目&#34;&gt;我的第一个数据可视化项目&lt;/h3&gt;
&lt;p&gt;比如，你可以直接把你在 Jupyter Notebook 里生成的前端可视化代码（HTML/JS）直接粘贴在这里：&lt;/p&gt;
&lt;div id=&#34;my-chart&#34; style=&#34;width: 600px; height: 400px; background: #f0f0f0; display: flex; align-items: center; justify-content: center;&#34;&gt;
&lt;!------
&lt;!DOCTYPE html&gt;
&lt;html lang=&#34;en&#34;&gt;
&lt;head&gt;
    &lt;meta charset=&#34;UTF-8&#34;&gt;
    &lt;meta name=&#34;viewport&#34; content=&#34;width=device-width, initial-scale=1.0&#34;&gt;
    &lt;title&gt;D3.js Solar System&lt;/title&gt;
    &lt;script src=&#34;https://d3js.org/d3.v7.min.js&#34;&gt;&lt;/script&gt;
    &lt;style&gt;
        body {
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background-color: #000;
            overflow: hidden; /* 防止滚动条出现 */
        }
        .solar-system {
            width: 800px;
            height: 800px;
        }
        /* 星空背景 */
        .stars {
            fill: white;
            opacity: 0.8;
        }
        /* 行星公转动画 */
        @keyframes orbit {
            from { transform: rotate(0deg); }
            to { transform: rotate(360deg); }
        }
        .orbit {
            animation: orbit linear infinite;
            transform-origin: center center;
        }
        /* 行星自转动画 */
        @keyframes spin {
            from { transform: rotate(0deg); }
            to { transform: rotate(-360deg); }
        }
        .planet-spin {
            animation: spin linear infinite;
            transform-origin: center center;
        }
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;div id=&amp;quot;solar-system-container&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;

&amp;lt;script&amp;gt;
    // 1. 定义太阳系数据
    const solarSystem = {
        sun: { radius: 40, color: &amp;quot;#FDB813&amp;quot; },
        planets: [
            { name: &amp;quot;水星&amp;quot;, radius: 8, color: &amp;quot;#A9A9A9&amp;quot;, distance: 100, orbitDuration: 4, spinDuration: 10 },
            { name: &amp;quot;金星&amp;quot;, radius: 12, color: &amp;quot;#FFC649&amp;quot;, distance: 160, orbitDuration: 8, spinDuration: 20 },
            { name: &amp;quot;地球&amp;quot;, radius: 14, color: &amp;quot;#6B93D6&amp;quot;, distance: 220, orbitDuration: 12, spinDuration: 5 },
            { name: &amp;quot;火星&amp;quot;, radius: 10, color: &amp;quot;#FF4D4D&amp;quot;, distance: 280, orbitDuration: 16, spinDuration: 15 },
            { name: &amp;quot;木星&amp;quot;, radius: 30, color: &amp;quot;#FFA726&amp;quot;, distance: 380, orbitDuration: 24, spinDuration: 3 },
            { name: &amp;quot;土星&amp;quot;, radius: 26, color: &amp;quot;#FFD95A&amp;quot;, distance: 480, orbitDuration: 30, spinDuration: 4, hasRing: true },
            { name: &amp;quot;天王星&amp;quot;, radius: 20, color: &amp;quot;#4FD0E7&amp;quot;, distance: 580, orbitDuration: 40, spinDuration: 8 },
            { name: &amp;quot;海王星&amp;quot;, radius: 20, color: &amp;quot;#4B70DD&amp;quot;, distance: 680, orbitDuration: 50, spinDuration: 10 }
        ]
    };

    // 2. 创建 SVG 画布
    const width = 800;
    const height = 800;
    const centerX = width / 2;
    const centerY = height / 2;

    const svg = d3.select(&amp;quot;#solar-system-container&amp;quot;)
        .append(&amp;quot;svg&amp;quot;)
        .attr(&amp;quot;width&amp;quot;, width)
        .attr(&amp;quot;height&amp;quot;, height)
        .attr(&amp;quot;viewBox&amp;quot;, `0 0 ${width} ${height}`)
        .attr(&amp;quot;preserveAspectRatio&amp;quot;, &amp;quot;xMidYMid meet&amp;quot;)
        .classed(&amp;quot;solar-system&amp;quot;, true);

    // 3. 绘制背景星空
    const starsCount = 200;
    const starsData = Array.from({ length: starsCount }, () =&amp;gt; ({
        x: Math.random() * width,
        y: Math.random() * height,
        r: Math.random() * 1.5
    }));

    svg.selectAll(&amp;quot;.star&amp;quot;)
        .data(starsData)
        .enter()
        .append(&amp;quot;circle&amp;quot;)
        .attr(&amp;quot;class&amp;quot;, &amp;quot;stars&amp;quot;)
        .attr(&amp;quot;cx&amp;quot;, d =&amp;gt; d.x)
        .attr(&amp;quot;cy&amp;quot;, d =&amp;gt; d.y)
        .attr(&amp;quot;r&amp;quot;, d =&amp;gt; d.r);

    // 4. 绘制太阳
    svg.append(&amp;quot;circle&amp;quot;)
        .attr(&amp;quot;cx&amp;quot;, centerX)
        .attr(&amp;quot;cy&amp;quot;, centerY)
        .attr(&amp;quot;r&amp;quot;, solarSystem.sun.radius)
        .attr(&amp;quot;fill&amp;quot;, solarSystem.sun.color)
        .attr(&amp;quot;filter&amp;quot;, &amp;quot;url(#glow)&amp;quot;); // 添加发光滤镜

    // 5. 绘制行星及其轨道
    const planetGroups = svg.selectAll(&amp;quot;.planet-group&amp;quot;)
        .data(solarSystem.planets)
        .enter()
        .append(&amp;quot;g&amp;quot;)
        .attr(&amp;quot;class&amp;quot;, &amp;quot;planet-group&amp;quot;)
        .attr(&amp;quot;transform&amp;quot;, `translate(${centerX}, ${centerY})`);
    
    // 轨道线
    planetGroups.append(&amp;quot;circle&amp;quot;)
        .attr(&amp;quot;class&amp;quot;, &amp;quot;orbit&amp;quot;)
        .attr(&amp;quot;r&amp;quot;, d =&amp;gt; d.distance)
        .attr(&amp;quot;fill&amp;quot;, &amp;quot;none&amp;quot;)
        .attr(&amp;quot;stroke&amp;quot;, &amp;quot;rgba(255, 255, 255, 0.2)&amp;quot;)
        .attr(&amp;quot;stroke-width&amp;quot;, 1)
        .style(&amp;quot;animation-duration&amp;quot;, d =&amp;gt; `${d.orbitDuration}s`);

    // 行星本体
    const planets = planetGroups.append(&amp;quot;g&amp;quot;)
        .attr(&amp;quot;class&amp;quot;, &amp;quot;planet-spin&amp;quot;)
        .style(&amp;quot;animation-duration&amp;quot;, d =&amp;gt; `${d.spinDuration}s`);

    planets.append(&amp;quot;circle&amp;quot;)
        .attr(&amp;quot;cx&amp;quot;, d =&amp;gt; d.distance)
        .attr(&amp;quot;cy&amp;quot;, 0)
        .attr(&amp;quot;r&amp;quot;, d =&amp;gt; d.radius)
        .attr(&amp;quot;fill&amp;quot;, d =&amp;gt; d.color);
    
    // 土星环
    planets.filter(d =&amp;gt; d.hasRing)
        .append(&amp;quot;ellipse&amp;quot;)
        .attr(&amp;quot;cx&amp;quot;, d =&amp;gt; d.distance)
        .attr(&amp;quot;cy&amp;quot;, 0)
        .attr(&amp;quot;rx&amp;quot;, d =&amp;gt; d.radius * 2.5)
        .attr(&amp;quot;ry&amp;quot;, d =&amp;gt; d.radius * 0.5)
        .attr(&amp;quot;fill&amp;quot;, &amp;quot;none&amp;quot;)
        .attr(&amp;quot;stroke&amp;quot;, d =&amp;gt; d3.color(d.color).brighter(0.5))
        .attr(&amp;quot;stroke-width&amp;quot;, 3)
        .attr(&amp;quot;opacity&amp;quot;, 0.8)
        .attr(&amp;quot;transform&amp;quot;, `rotate(-20, ${d =&amp;gt; d.distance}, 0)`);

    // 6. 添加太阳光晕滤镜
    const defs = svg.append(&amp;quot;defs&amp;quot;);
    const filter = defs.append(&amp;quot;filter&amp;quot;)
        .attr(&amp;quot;id&amp;quot;, &amp;quot;glow&amp;quot;)
        .attr(&amp;quot;x&amp;quot;, &amp;quot;-50%&amp;quot;)
        .attr(&amp;quot;y&amp;quot;, &amp;quot;-50%&amp;quot;)
        .attr(&amp;quot;width&amp;quot;, &amp;quot;200%&amp;quot;)
        .attr(&amp;quot;height&amp;quot;, &amp;quot;200%&amp;quot;);
    
    filter.append(&amp;quot;feGaussianBlur&amp;quot;)
        .attr(&amp;quot;stdDeviation&amp;quot;, &amp;quot;8&amp;quot;)
        .attr(&amp;quot;result&amp;quot;, &amp;quot;coloredBlur&amp;quot;);
        
    const feMerge = filter.append(&amp;quot;feMerge&amp;quot;);
    feMerge.append(&amp;quot;feMergeNode&amp;quot;).attr(&amp;quot;in&amp;quot;, &amp;quot;coloredBlur&amp;quot;);
    feMerge.append(&amp;quot;feMergeNode&amp;quot;).attr(&amp;quot;in&amp;quot;, &amp;quot;SourceGraphic&amp;quot;);

&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/body&gt;
&lt;/html&gt;
------&gt;
&lt;!-- 1. 样式部分：直接写在这里，或者放在文章的 &lt;head&gt; 里 --&gt;
&lt;!-----------------
&lt;style&gt;
    /* 星空背景，覆盖父容器的灰色背景 */
    #my-chart {
        background-color: #000 !important; /* 强制变黑，配合太空主题 */
        position: relative;
        overflow: hidden;
    }
    /* 星空点点 */
    .stars {
        fill: white;
        opacity: 0.8;
    }
    /* 行星公转动画 */
    @keyframes orbit {
        from { transform: rotate(0deg); }
        to { transform: rotate(360deg); }
    }
    .orbit {
        animation: orbit linear infinite;
        transform-origin: center center;
    }
    /* 行星自转动画 */
    @keyframes spin {
        from { transform: rotate(0deg); }
        to { transform: rotate(-360deg); }
    }
    .planet-spin {
        animation: spin linear infinite;
        transform-origin: center center;
    }
&lt;/style&gt;
--------------&gt;
&lt;!-- 2. 内容容器（保留你的原ID，但清空内容） --&gt;
&lt;p&gt;/*&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
