{"id":1182611,"date":"2025-01-15T19:05:17","date_gmt":"2025-01-15T11:05:17","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1182611.html"},"modified":"2025-01-15T19:05:19","modified_gmt":"2025-01-15T11:05:19","slug":"python%e5%a6%82%e4%bd%95%e7%bb%9f%e8%ae%a1%e8%be%93%e5%87%ba%e7%9a%84%e7%bb%93%e6%9e%9c","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1182611.html","title":{"rendered":"python\u5982\u4f55\u7edf\u8ba1\u8f93\u51fa\u7684\u7ed3\u679c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25130539\/1e0e3f41-b9f7-4d3f-9545-ec8f2806e12f.webp\" alt=\"python\u5982\u4f55\u7edf\u8ba1\u8f93\u51fa\u7684\u7ed3\u679c\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u7edf\u8ba1\u8f93\u51fa\u7ed3\u679c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3001\u5e93\u51fd\u6570\u4ee5\u53ca\u81ea\u5b9a\u4e49\u51fd\u6570\u7b49\u3002\u4ee5\u4e0b\u662f\u51e0\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u8fdb\u884c\u7edf\u8ba1\u3001\u5229\u7528NumPy\u548cPandas\u5e93\u8fdb\u884c\u7edf\u8ba1\u3001\u4f7f\u7528Counter\u548cdefaultdict\u8fdb\u884c\u7edf\u8ba1\u3001\u7f16\u5199\u81ea\u5b9a\u4e49\u7edf\u8ba1\u51fd\u6570\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u7edf\u8ba1\u8f93\u51fa\u7684\u7ed3\u679c\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u4efb\u52a1\uff0c\u65e0\u8bba\u662f\u7edf\u8ba1\u7b80\u5355\u7684\u6570\u636e\u5982\u5e73\u5747\u503c\u3001\u6700\u5927\u503c\uff0c\u8fd8\u662f\u590d\u6742\u7684\u6570\u636e\u5982\u9891\u7387\u5206\u5e03\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u2014\u2014\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u8fdb\u884c\u7edf\u8ba1\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u8fdb\u884c\u7edf\u8ba1<\/h3>\n<\/p>\n<p><p>Python\u5185\u7f6e\u4e86\u4e00\u4e9b\u975e\u5e38\u5f3a\u5927\u7684\u51fd\u6570\u548c\u65b9\u6cd5\uff0c\u53ef\u4ee5\u7528\u4e8e\u57fa\u672c\u7684\u7edf\u8ba1\u5206\u6790\u3002\u4ee5\u4e0b\u662f\u51e0\u4e2a\u5e38\u7528\u7684\u5185\u7f6e\u51fd\u6570\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>sum()<\/strong>: \u8ba1\u7b97\u603b\u548c<\/li>\n<li><strong>len()<\/strong>: \u8ba1\u7b97\u5143\u7d20\u6570\u91cf<\/li>\n<li><strong>max()<\/strong>: \u627e\u5230\u6700\u5927\u503c<\/li>\n<li><strong>min()<\/strong>: \u627e\u5230\u6700\u5c0f\u503c<\/li>\n<li><strong>sorted()<\/strong>: \u5bf9\u6570\u636e\u8fdb\u884c\u6392\u5e8f<\/li>\n<\/ul>\n<p><p>\u4f8b\u5982\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u5305\u542b\u6570\u5b57\u7684\u5217\u8868\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9b\u5185\u7f6e\u51fd\u6570\u6765\u8fdb\u884c\u57fa\u672c\u7684\u7edf\u8ba1\u5206\u6790\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<\/p>\n<p>total_sum = sum(data)<\/p>\n<p>count = len(data)<\/p>\n<p>maximum = max(data)<\/p>\n<p>minimum = min(data)<\/p>\n<p>sorted_data = sorted(data)<\/p>\n<p>print(&quot;\u603b\u548c:&quot;, total_sum)<\/p>\n<p>print(&quot;\u5143\u7d20\u6570\u91cf:&quot;, count)<\/p>\n<p>print(&quot;\u6700\u5927\u503c:&quot;, maximum)<\/p>\n<p>print(&quot;\u6700\u5c0f\u503c:&quot;, minimum)<\/p>\n<p>print(&quot;\u6392\u5e8f\u540e\u7684\u6570\u636e:&quot;, sorted_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u83b7\u5f97\u6570\u636e\u7684\u603b\u548c\u3001\u6570\u91cf\u3001\u6700\u5927\u503c\u3001\u6700\u5c0f\u503c\u4ee5\u53ca\u6392\u5e8f\u540e\u7684\u6570\u636e\u3002\u8fd9\u4e9b\u57fa\u672c\u7684\u7edf\u8ba1\u4fe1\u606f\u5728\u5f88\u591a\u60c5\u51b5\u4e0b\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u8fdb\u884c\u7edf\u8ba1<\/h3>\n<\/p>\n<p><p>Python\u5185\u7f6e\u4e86\u4e00\u7cfb\u5217\u51fd\u6570\uff0c\u53ef\u4ee5\u7528\u6765\u5feb\u901f\u7edf\u8ba1\u548c\u5206\u6790\u6570\u636e\u3002\u8fd9\u4e9b\u51fd\u6570\u7b80\u5355\u6613\u7528\uff0c\u9002\u5408\u5904\u7406\u8f83\u5c0f\u89c4\u6a21\u7684\u6570\u636e\u96c6\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528sum()\u548clen()\u51fd\u6570<\/h4>\n<\/p>\n<p><p><code>sum()<\/code>\u51fd\u6570\u7528\u4e8e\u8ba1\u7b97\u6570\u636e\u7684\u603b\u548c\uff0c<code>len()<\/code>\u51fd\u6570\u7528\u4e8e\u7edf\u8ba1\u6570\u636e\u5143\u7d20\u7684\u6570\u91cf\u3002\u8fd9\u4e24\u4e2a\u51fd\u6570\u7ed3\u5408\u4f7f\u7528\uff0c\u53ef\u4ee5\u8ba1\u7b97\u6570\u636e\u7684\u5e73\u5747\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<\/p>\n<p>total_sum = sum(data)<\/p>\n<p>count = len(data)<\/p>\n<p>average = total_sum \/ count<\/p>\n<p>print(&quot;\u603b\u548c:&quot;, total_sum)<\/p>\n<p>print(&quot;\u5143\u7d20\u6570\u91cf:&quot;, count)<\/p>\n<p>print(&quot;\u5e73\u5747\u503c:&quot;, average)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528<code>sum()<\/code>\u51fd\u6570\u8ba1\u7b97\u6570\u636e\u7684\u603b\u548c\uff0c\u7136\u540e\u4f7f\u7528<code>len()<\/code>\u51fd\u6570\u7edf\u8ba1\u6570\u636e\u7684\u6570\u91cf\uff0c\u6700\u540e\u901a\u8fc7\u4e24\u8005\u7684\u6bd4\u503c\u8ba1\u7b97\u5e73\u5747\u503c\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528max()\u548cmin()\u51fd\u6570<\/h4>\n<\/p>\n<p><p><code>max()<\/code>\u51fd\u6570\u7528\u4e8e\u627e\u5230\u6570\u636e\u4e2d\u7684\u6700\u5927\u503c\uff0c<code>min()<\/code>\u51fd\u6570\u7528\u4e8e\u627e\u5230\u6570\u636e\u4e2d\u7684\u6700\u5c0f\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<\/p>\n<p>maximum = max(data)<\/p>\n<p>minimum = min(data)<\/p>\n<p>print(&quot;\u6700\u5927\u503c:&quot;, maximum)<\/p>\n<p>print(&quot;\u6700\u5c0f\u503c:&quot;, minimum)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u627e\u5230\u6570\u636e\u4e2d\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u4f7f\u7528sorted()\u51fd\u6570<\/h4>\n<\/p>\n<p><p><code>sorted()<\/code>\u51fd\u6570\u7528\u4e8e\u5bf9\u6570\u636e\u8fdb\u884c\u6392\u5e8f\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u5217\u8868\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<code>sorted()<\/code>\u51fd\u6570\u6765\u83b7\u53d6\u6570\u636e\u7684\u4e2d\u4f4d\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<\/p>\n<p>sorted_data = sorted(data)<\/p>\n<p>print(&quot;\u6392\u5e8f\u540e\u7684\u6570\u636e:&quot;, sorted_data)<\/p>\n<h2><strong>\u8ba1\u7b97\u4e2d\u4f4d\u6570<\/strong><\/h2>\n<p>middle_index = len(sorted_data) \/\/ 2<\/p>\n<p>if len(sorted_data) % 2 == 0:<\/p>\n<p>    median = (sorted_data[middle_index - 1] + sorted_data[middle_index]) \/ 2<\/p>\n<p>else:<\/p>\n<p>    median = sorted_data[middle_index]<\/p>\n<p>print(&quot;\u4e2d\u4f4d\u6570:&quot;, median)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528<code>sorted()<\/code>\u51fd\u6570\u5bf9\u6570\u636e\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\u901a\u8fc7\u7d22\u5f15\u8ba1\u7b97\u4e2d\u4f4d\u6570\u3002\u5982\u679c\u6570\u636e\u5143\u7d20\u7684\u6570\u91cf\u662f\u5076\u6570\uff0c\u4e2d\u4f4d\u6570\u662f\u4e2d\u95f4\u4e24\u4e2a\u6570\u7684\u5e73\u5747\u503c\uff1b\u5982\u679c\u6570\u636e\u5143\u7d20\u7684\u6570\u91cf\u662f\u5947\u6570\uff0c\u4e2d\u4f4d\u6570\u662f\u4e2d\u95f4\u7684\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5229\u7528NumPy\u548cPandas\u5e93\u8fdb\u884c\u7edf\u8ba1<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u6570\u636e\u5206\u6790\u4efb\u52a1\uff0cPython\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u5982NumPy\u548cPandas\u3002\u8fd9\u4e9b\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u51fd\u6570\u548c\u65b9\u6cd5\uff0c\u53ef\u4ee5\u9ad8\u6548\u5730\u8fdb\u884c\u6570\u636e\u7edf\u8ba1\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528NumPy\u8fdb\u884c\u7edf\u8ba1<\/h4>\n<\/p>\n<p><p>NumPy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u503c\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u591a\u79cd\u7edf\u8ba1\u51fd\u6570\uff0c\u5982<code>mean()<\/code>\u3001<code>median()<\/code>\u3001<code>std()<\/code>\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>data = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])<\/p>\n<p>average = np.mean(data)<\/p>\n<p>median = np.median(data)<\/p>\n<p>std_dev = np.std(data)<\/p>\n<p>print(&quot;\u5e73\u5747\u503c:&quot;, average)<\/p>\n<p>print(&quot;\u4e2d\u4f4d\u6570:&quot;, median)<\/p>\n<p>print(&quot;\u6807\u51c6\u5dee:&quot;, std_dev)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u8ba1\u7b97\u6570\u636e\u7684\u5e73\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u548c\u6807\u51c6\u5dee\u3002NumPy\u7684\u8ba1\u7b97\u901f\u5ea6\u975e\u5e38\u5feb\uff0c\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528Pandas\u8fdb\u884c\u7edf\u8ba1<\/h4>\n<\/p>\n<p><p>Pandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u7279\u522b\u9002\u5408\u5904\u7406\u7ed3\u6784\u5316\u6570\u636e\u3002Pandas\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u636e\u64cd\u4f5c\u548c\u7edf\u8ba1\u51fd\u6570\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u5206\u6790\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])<\/p>\n<p>average = data.mean()<\/p>\n<p>median = data.median()<\/p>\n<p>std_dev = data.std()<\/p>\n<p>print(&quot;\u5e73\u5747\u503c:&quot;, average)<\/p>\n<p>print(&quot;\u4e2d\u4f4d\u6570:&quot;, median)<\/p>\n<p>print(&quot;\u6807\u51c6\u5dee:&quot;, std_dev)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Pandas\u7684<code>Series<\/code>\u5bf9\u8c61\u6765\u5b58\u50a8\u6570\u636e\uff0c\u5e76\u4f7f\u7528<code>mean()<\/code>\u3001<code>median()<\/code>\u548c<code>std()<\/code>\u65b9\u6cd5\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u3002Pandas\u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591a\u5176\u4ed6\u6709\u7528\u7684\u51fd\u6570\uff0c\u5982<code>sum()<\/code>\u3001<code>max()<\/code>\u3001<code>min()<\/code>\u7b49\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u7edf\u8ba1\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528Counter\u548cdefaultdict\u8fdb\u884c\u7edf\u8ba1<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u9891\u7387\u5206\u5e03\u7b49\u4efb\u52a1\u65f6\uff0cPython\u7684<code>collections<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\uff0c\u5982<code>Counter<\/code>\u548c<code>defaultdict<\/code>\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u7edf\u8ba1\u548c\u9891\u7387\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Counter\u8fdb\u884c\u7edf\u8ba1<\/h4>\n<\/p>\n<p><p><code>Counter<\/code>\u662f\u4e00\u4e2a\u4e13\u95e8\u7528\u4e8e\u8ba1\u6570\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u8f7b\u677e\u7edf\u8ba1\u6570\u636e\u5143\u7d20\u7684\u9891\u7387\u5206\u5e03\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import Counter<\/p>\n<p>data = [&#39;apple&#39;, &#39;banana&#39;, &#39;apple&#39;, &#39;orange&#39;, &#39;banana&#39;, &#39;apple&#39;]<\/p>\n<p>counter = Counter(data)<\/p>\n<p>print(&quot;\u9891\u7387\u5206\u5e03:&quot;, counter)<\/p>\n<p>print(&quot;\u6700\u5e38\u89c1\u7684\u5143\u7d20:&quot;, counter.most_common(1))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>Counter<\/code>\u7edf\u8ba1\u6570\u636e\u5143\u7d20\u7684\u9891\u7387\u5206\u5e03\uff0c\u5e76\u4f7f\u7528<code>most_common()<\/code>\u65b9\u6cd5\u627e\u5230\u6700\u5e38\u89c1\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528defaultdict\u8fdb\u884c\u7edf\u8ba1<\/h4>\n<\/p>\n<p><p><code>defaultdict<\/code>\u662f\u4e00\u4e2a\u5e26\u6709\u9ed8\u8ba4\u503c\u7684\u5b57\u5178\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u7edf\u8ba1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import defaultdict<\/p>\n<p>data = [&#39;apple&#39;, &#39;banana&#39;, &#39;apple&#39;, &#39;orange&#39;, &#39;banana&#39;, &#39;apple&#39;]<\/p>\n<p>frequency = defaultdict(int)<\/p>\n<p>for item in data:<\/p>\n<p>    frequency[item] += 1<\/p>\n<p>print(&quot;\u9891\u7387\u5206\u5e03:&quot;, frequency)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>defaultdict<\/code>\u7edf\u8ba1\u6570\u636e\u5143\u7d20\u7684\u9891\u7387\u5206\u5e03\u3002<code>defaultdict<\/code>\u7684\u4f7f\u7528\u975e\u5e38\u7075\u6d3b\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u6307\u5b9a\u9ed8\u8ba4\u503c\u7684\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u7f16\u5199\u81ea\u5b9a\u4e49\u7edf\u8ba1\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u7f16\u5199\u81ea\u5b9a\u4e49\u7684\u7edf\u8ba1\u51fd\u6570\u6765\u6ee1\u8db3\u7279\u5b9a\u7684\u9700\u6c42\u3002\u4ee5\u4e0b\u662f\u51e0\u4e2a\u5e38\u89c1\u7684\u81ea\u5b9a\u4e49\u7edf\u8ba1\u51fd\u6570\u7684\u4f8b\u5b50\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u8ba1\u7b97\u4f17\u6570\u7684\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u4f17\u6570\u662f\u6570\u636e\u96c6\u4e2d\u51fa\u73b0\u9891\u7387\u6700\u9ad8\u7684\u503c\u3002\u6211\u4eec\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u6570\u636e\u7684\u4f17\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def calculate_mode(data):<\/p>\n<p>    frequency = Counter(data)<\/p>\n<p>    mode = frequency.most_common(1)[0][0]<\/p>\n<p>    return mode<\/p>\n<p>data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10]<\/p>\n<p>mode = calculate_mode(data)<\/p>\n<p>print(&quot;\u4f17\u6570:&quot;, mode)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528<code>Counter<\/code>\u7edf\u8ba1\u6570\u636e\u5143\u7d20\u7684\u9891\u7387\u5206\u5e03\uff0c\u7136\u540e\u901a\u8fc7<code>most_common()<\/code>\u65b9\u6cd5\u627e\u5230\u4f17\u6570\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u8ba1\u7b97\u65b9\u5dee\u7684\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u65b9\u5dee\u662f\u6570\u636e\u96c6\u4e2d\u5404\u4e2a\u6570\u636e\u4e0e\u5e73\u5747\u503c\u4e4b\u95f4\u7684\u5dee\u7684\u5e73\u65b9\u7684\u5e73\u5747\u503c\u3002\u6211\u4eec\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u6570\u636e\u7684\u65b9\u5dee\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def calculate_variance(data):<\/p>\n<p>    average = sum(data) \/ len(data)<\/p>\n<p>    variance = sum((x - average)  2 for x in data) \/ len(data)<\/p>\n<p>    return variance<\/p>\n<p>data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<\/p>\n<p>variance = calculate_variance(data)<\/p>\n<p>print(&quot;\u65b9\u5dee:&quot;, variance)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u8ba1\u7b97\u6570\u636e\u7684\u5e73\u5747\u503c\uff0c\u7136\u540e\u8ba1\u7b97\u6bcf\u4e2a\u6570\u636e\u4e0e\u5e73\u5747\u503c\u4e4b\u95f4\u7684\u5dee\u7684\u5e73\u65b9\uff0c\u6700\u540e\u6c42\u8fd9\u4e9b\u5e73\u65b9\u7684\u5e73\u5747\u503c\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u8ba1\u7b97\u6807\u51c6\u5dee\u7684\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u6807\u51c6\u5dee\u662f\u65b9\u5dee\u7684\u5e73\u65b9\u6839\u3002\u6211\u4eec\u53ef\u4ee5\u57fa\u4e8e\u65b9\u5dee\u7684\u8ba1\u7b97\u51fd\u6570\uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u6570\u636e\u7684\u6807\u51c6\u5dee\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def calculate_standard_deviation(data):<\/p>\n<p>    variance = calculate_variance(data)<\/p>\n<p>    standard_deviation = variance  0.5<\/p>\n<p>    return standard_deviation<\/p>\n<p>data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<\/p>\n<p>standard_deviation = calculate_standard_deviation(data)<\/p>\n<p>print(&quot;\u6807\u51c6\u5dee:&quot;, standard_deviation)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u8c03\u7528\u8ba1\u7b97\u65b9\u5dee\u7684\u51fd\u6570\uff0c\u7136\u540e\u8ba1\u7b97\u65b9\u5dee\u7684\u5e73\u65b9\u6839\uff0c\u5373\u5f97\u5230\u6807\u51c6\u5dee\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u7edf\u8ba1\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5bf9\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u3002\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u662f\u6309\u65f6\u95f4\u987a\u5e8f\u6392\u5217\u7684\u6570\u636e\uff0c\u901a\u5e38\u7528\u4e8e\u91d1\u878d\u3001\u6c14\u8c61\u7b49\u9886\u57df\u7684\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Pandas\u5904\u7406\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/h4>\n<\/p>\n<p><p>Pandas\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u65f6\u95f4\u5e8f\u5217\u5904\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u7edf\u8ba1\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/strong><\/h2>\n<p>date_range = pd.date_range(start=&#39;2023-01-01&#39;, periods=10, freq=&#39;D&#39;)<\/p>\n<p>data = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=date_range)<\/p>\n<h2><strong>\u7edf\u8ba1\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u57fa\u672c\u4fe1\u606f<\/strong><\/h2>\n<p>average = data.mean()<\/p>\n<p>median = data.median()<\/p>\n<p>std_dev = data.std()<\/p>\n<p>print(&quot;\u5e73\u5747\u503c:&quot;, average)<\/p>\n<p>print(&quot;\u4e2d\u4f4d\u6570:&quot;, median)<\/p>\n<p>print(&quot;\u6807\u51c6\u5dee:&quot;, std_dev)<\/p>\n<h2><strong>\u8ba1\u7b97\u6eda\u52a8\u5e73\u5747\u503c<\/strong><\/h2>\n<p>rolling_average = data.rolling(window=3).mean()<\/p>\n<p>print(&quot;\u6eda\u52a8\u5e73\u5747\u503c:\\n&quot;, rolling_average)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u65f6\u95f4\u5e8f\u5217\u6570\u636e\uff0c\u7136\u540e\u4f7f\u7528Pandas\u7684\u7edf\u8ba1\u51fd\u6570\u8fdb\u884c\u57fa\u672c\u7684\u7edf\u8ba1\u5206\u6790\u3002\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>rolling()<\/code>\u65b9\u6cd5\u8ba1\u7b97\u6eda\u52a8\u5e73\u5747\u503c\uff0c\u8fd9\u5728\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u4e2d\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528Matplotlib\u53ef\u89c6\u5316\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u5728\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u4e2d\uff0c\u6570\u636e\u7684\u53ef\u89c6\u5316\u975e\u5e38\u91cd\u8981\u3002Matplotlib\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u7ed8\u56fe\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u7684\u53ef\u89c6\u5316\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/strong><\/h2>\n<p>date_range = pd.date_range(start=&#39;2023-01-01&#39;, periods=10, freq=&#39;D&#39;)<\/p>\n<p>data = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=date_range)<\/p>\n<h2><strong>\u7ed8\u5236\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/strong><\/h2>\n<p>plt.figure(figsize=(10, 6))<\/p>\n<p>plt.plot(data, label=&#39;\u539f\u59cb\u6570\u636e&#39;)<\/p>\n<p>plt.plot(data.rolling(window=3).mean(), label=&#39;\u6eda\u52a8\u5e73\u5747\u503c&#39;, linestyle=&#39;--&#39;)<\/p>\n<p>plt.xlabel(&#39;\u65e5\u671f&#39;)<\/p>\n<p>plt.ylabel(&#39;\u503c&#39;)<\/p>\n<p>plt.title(&#39;\u65f6\u95f4\u5e8f\u5217\u6570\u636e&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Matplotlib\u7ed8\u5236\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u6298\u7ebf\u56fe\uff0c\u5e76\u6dfb\u52a0\u6eda\u52a8\u5e73\u5747\u503c\u7684\u66f2\u7ebf\u3002\u901a\u8fc7\u8fd9\u79cd\u53ef\u89c6\u5316\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u76f4\u89c2\u5730\u89c2\u5bdf\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u53d8\u5316\u8d8b\u52bf\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u7edf\u8ba1\u5206\u7ec4\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5bf9\u5206\u7ec4\u6570\u636e\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u3002\u5206\u7ec4\u6570\u636e\u662f\u6839\u636e\u67d0\u4e9b\u7279\u5f81\u5c06\u6570\u636e\u5206\u6210\u4e0d\u540c\u7684\u7ec4\uff0c\u7136\u540e\u5bf9\u6bcf\u7ec4\u6570\u636e\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Pandas\u8fdb\u884c\u5206\u7ec4\u7edf\u8ba1<\/h4>\n<\/p>\n<p><p>Pandas\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5206\u7ec4\u529f\u80fd\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bf9\u5206\u7ec4\u6570\u636e\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u6846<\/strong><\/h2>\n<p>data = pd.DataFrame({<\/p>\n<p>    &#39;\u7c7b\u522b&#39;: [&#39;A&#39;, &#39;B&#39;, &#39;A&#39;, &#39;B&#39;, &#39;A&#39;, &#39;B&#39;, &#39;A&#39;, &#39;B&#39;],<\/p>\n<p>    &#39;\u503c&#39;: [1, 2, 3, 4, 5, 6, 7, 8]<\/p>\n<p>})<\/p>\n<h2><strong>\u5206\u7ec4\u7edf\u8ba1<\/strong><\/h2>\n<p>grouped = data.groupby(&#39;\u7c7b\u522b&#39;).agg({<\/p>\n<p>    &#39;\u503c&#39;: [&#39;sum&#39;, &#39;mean&#39;, &#39;max&#39;, &#39;min&#39;]<\/p>\n<p>})<\/p>\n<p>print(grouped)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u6846\uff0c\u7136\u540e\u4f7f\u7528<code>groupby()<\/code>\u65b9\u6cd5\u6839\u636e\u7c7b\u522b\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7ec4\uff0c\u5e76\u4f7f\u7528<code>agg()<\/code>\u65b9\u6cd5\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bf9\u5206\u7ec4\u6570\u636e\u8fdb\u884c\u591a\u79cd\u7edf\u8ba1\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528SQLAlchemy\u8fdb\u884c\u5206\u7ec4\u7edf\u8ba1<\/h4>\n<\/p>\n<p><p>\u5728\u5904\u7406\u6570\u636e\u5e93\u4e2d\u7684\u5206\u7ec4\u6570\u636e\u65f6\uff0cSQLAlchemy\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\u3002SQLAlchemy\u662f\u4e00\u4e2aPython SQL\u5de5\u5177\u5305\u548c\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\uff08ORM\uff09\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sqlalchemy import create_engine, Column, Integer, String, func<\/p>\n<p>from sqlalchemy.ext.declarative import declarative_base<\/p>\n<p>from sqlalchemy.orm import sessionmaker<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u5e93\u5f15\u64ce<\/strong><\/h2>\n<p>engine = create_engine(&#39;sqlite:\/\/\/:memory:&#39;)<\/p>\n<p>Base = declarative_base()<\/p>\n<h2><strong>\u5b9a\u4e49\u6570\u636e\u8868<\/strong><\/h2>\n<p>class Data(Base):<\/p>\n<p>    __tablename__ = &#39;data&#39;<\/p>\n<p>    id = Column(Integer, primary_key=True)<\/p>\n<p>    category = Column(String)<\/p>\n<p>    value = Column(Integer)<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u8868<\/strong><\/h2>\n<p>Base.metadata.create_all(engine)<\/p>\n<h2><strong>\u521b\u5efa\u4f1a\u8bdd<\/strong><\/h2>\n<p>Session = sessionmaker(bind=engine)<\/p>\n<p>session = Session()<\/p>\n<h2><strong>\u63d2\u5165\u6570\u636e<\/strong><\/h2>\n<p>session.add_all([<\/p>\n<p>    Data(category=&#39;A&#39;, value=1),<\/p>\n<p>    Data(category=&#39;B&#39;, value=2),<\/p>\n<p>    Data(category=&#39;A&#39;, value=3),<\/p>\n<p>    Data(category=&#39;B&#39;, value=4),<\/p>\n<p>    Data(category=&#39;A&#39;, value=5),<\/p>\n<p>    Data(category=&#39;B&#39;, value=6),<\/p>\n<p>    Data(category=&#39;A&#39;, value=7),<\/p>\n<p>    Data(category=&#39;B&#39;, value=8),<\/p>\n<p>])<\/p>\n<p>session.commit()<\/p>\n<h2><strong>\u5206\u7ec4\u7edf\u8ba1<\/strong><\/h2>\n<p>results = session.query(<\/p>\n<p>    Data.category,<\/p>\n<p>    func.sum(Data.value).label(&#39;sum&#39;),<\/p>\n<p>    func.avg(Data.value).label(&#39;average&#39;),<\/p>\n<p>    func.max(Data.value).label(&#39;max&#39;),<\/p>\n<p>    func.min(Data.value).label(&#39;min&#39;)<\/p>\n<p>).group_by(Data.category).all()<\/p>\n<p>for result in results:<\/p>\n<p>    print(f&quot;\u7c7b\u522b: {result.category}, \u603b\u548c: {result.sum}, \u5e73\u5747\u503c: {result.average}, \u6700\u5927\u503c: {result.max}, \u6700\u5c0f\u503c: {result.min}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528SQLAlchemy\u521b\u5efa\u4e00\u4e2a\u5185\u5b58\u6570\u636e\u5e93\uff0c\u5e76\u5b9a\u4e49\u6570\u636e\u8868\u548c\u63d2\u5165\u6570\u636e\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528SQLAlchemy\u7684\u67e5\u8be2\u529f\u80fd\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7ec4\u7edf\u8ba1\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bf9\u6570\u636e\u5e93\u4e2d\u7684\u5206\u7ec4\u6570\u636e\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u7edf\u8ba1\u6587\u672c\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5728\u81ea\u7136\u8bed\u8a00\u5904\u7406\uff08NLP\uff09\u9886\u57df\uff0c\u6587\u672c\u6570\u636e\u7684\u7edf\u8ba1\u5206\u6790\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u4efb\u52a1\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684\u591a\u79cd\u5de5\u5177\u548c\u5e93\u6765\u7edf\u8ba1\u548c\u5206\u6790\u6587\u672c\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528collections.Counter\u7edf\u8ba1\u8bcd\u9891<\/h4>\n<\/p>\n<p><p><code>collections.Counter<\/code>\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u7edf\u8ba1\u6587\u672c\u4e2d\u7684\u8bcd\u9891\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import Counter<\/p>\n<p>import re<\/p>\n<p>text = &quot;Python is great. Python is dynamic. Python is easy to learn.&quot;<\/p>\n<h2><strong>\u5206\u8bcd<\/strong><\/h2>\n<p>words = re.findall(r&#39;\\w+&#39;, text.lower())<\/p>\n<h2><strong>\u7edf\u8ba1\u8bcd\u9891<\/strong><\/h2>\n<p>counter = Counter(words)<\/p>\n<p>print(&quot;\u8bcd\u9891\u5206\u5e03:&quot;, counter)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5bf9\u6587\u672c\u8fdb\u884c\u5206\u8bcd\uff0c\u7136\u540e\u4f7f\u7528<code>Counter<\/code>\u7edf\u8ba1\u8bcd\u9891\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u83b7\u5f97\u6587\u672c\u4e2d\u7684\u8bcd\u9891\u5206\u5e03\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528NLTK\u8fdb\u884c\u6587\u672c\u7edf\u8ba1\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u81ea\u7136\u8bed\u8a00\u5de5\u5177\u5305\uff08NLTK\uff09\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6587\u672c\u5904\u7406\u5e93\uff0c\u63d0\u4f9b\u4e86\u591a\u79cd\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6587\u672c\u7edf\u8ba1\u5206\u6790\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import nltk<\/p>\n<p>from nltk.probability import FreqDist<\/p>\n<p>nltk.download(&#39;punkt&#39;)<\/p>\n<p>text = &quot;Python is great. Python is dynamic. Python is easy to learn.&quot;<\/p>\n<h2><strong>\u5206\u8bcd<\/strong><\/h2>\n<p>words = nltk.word_tokenize(text.lower())<\/p>\n<h2><strong>\u7edf\u8ba1\u8bcd\u9891<\/strong><\/h2>\n<p>fdist = FreqDist(words)<\/p>\n<p>print(&quot;\u8bcd\u9891\u5206\u5e03:&quot;, fdist)<\/p>\n<h2><strong>\u627e\u5230\u6700\u5e38\u89c1\u7684\u8bcd<\/strong><\/h2>\n<p>print(&quot;\u6700\u5e38\u89c1\u7684\u8bcd:&quot;, fdist.most_common(3))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528NLTK\u7684\u5206\u8bcd\u5de5\u5177\u5bf9\u6587\u672c\u8fdb\u884c\u5206\u8bcd\uff0c\u7136\u540e\u4f7f\u7528<code>FreqDist<\/code>\u7edf\u8ba1\u8bcd\u9891\u3002\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>most_common()<\/code>\u65b9\u6cd5\u627e\u5230\u6700\u5e38\u89c1\u7684\u8bcd\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u7edf\u8ba1\u56fe\u50cf\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5728\u56fe\u50cf\u5904\u7406\u548c\u8ba1\u7b97\u673a\u89c6\u89c9\u9886\u57df\uff0c\u7edf\u8ba1\u56fe\u50cf\u6570\u636e\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u4efb\u52a1\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684\u591a\u79cd\u5de5\u5177\u548c\u5e93\u6765\u7edf\u8ba1\u548c\u5206\u6790\u56fe\u50cf\u6570\u636e\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u7edf\u8ba1\u8f93\u51fa\u7ed3\u679c\u7684\u6570\u91cf\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>len()<\/code>\u51fd\u6570\u6765\u7edf\u8ba1\u8f93\u51fa\u7ed3\u679c\u7684\u6570\u91cf\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u5217\u8868\u6216\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u7b80\u5355\u5730\u4f7f\u7528<code>len(my_list)<\/code>\u6216<code>len(my_string)<\/code>\u6765\u83b7\u53d6\u5143\u7d20\u6216\u5b57\u7b26\u7684\u6570\u91cf\u3002\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u76f4\u89c2\u4e14\u6613\u4e8e\u5b9e\u73b0\u3002<\/p>\n<p><strong>Python\u4e2d\u6709\u54ea\u4e9b\u5e93\u53ef\u4ee5\u5e2e\u52a9\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\uff1f<\/strong><br \/>Python\u6709\u8bb8\u591a\u5f3a\u5927\u7684\u5e93\u53ef\u4ee5\u7528\u4e8e\u7edf\u8ba1\u5206\u6790\uff0c\u6bd4\u5982<code>pandas<\/code>\u3001<code>numpy<\/code>\u548c<code>scipy<\/code>\u3002<code>pandas<\/code>\u63d0\u4f9b\u4e86\u6570\u636e\u7ed3\u6784\u548c\u6570\u636e\u5206\u6790\u5de5\u5177\uff0c\u975e\u5e38\u9002\u5408\u5904\u7406\u6570\u636e\u96c6\uff1b<code>numpy<\/code>\u5219\u4e13\u6ce8\u4e8e\u6570\u503c\u8ba1\u7b97\uff0c\u652f\u6301\u591a\u7ef4\u6570\u7ec4\u548c\u77e9\u9635\u64cd\u4f5c\uff1b\u800c<code>scipy<\/code>\u5219\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7ea7\u7684\u7edf\u8ba1\u51fd\u6570\u548c\u7b97\u6cd5\uff0c\u53ef\u4ee5\u8fdb\u884c\u590d\u6742\u7684\u6570\u636e\u5206\u6790\u3002<\/p>\n<p><strong>\u5982\u4f55\u5c06\u7edf\u8ba1\u7ed3\u679c\u53ef\u89c6\u5316\uff1f<\/strong><br \/>\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\u7edf\u8ba1\u7ed3\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>matplotlib<\/code>\u6216<code>seaborn<\/code>\u7b49\u53ef\u89c6\u5316\u5e93\u3002\u8fd9\u4e9b\u5e93\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u5c06\u6570\u636e\u4ee5\u56fe\u8868\u7684\u5f62\u5f0f\u5448\u73b0\uff0c\u4ece\u800c\u66f4\u76f4\u89c2\u5730\u5206\u6790\u6570\u636e\u7684\u5206\u5e03\u548c\u8d8b\u52bf\u3002\u4f8b\u5982\uff0c\u901a\u8fc7<code>plt.plot()<\/code>\u53ef\u4ee5\u7ed8\u5236\u7ebf\u56fe\uff0c\u4f7f\u7528<code>sns.barplot()<\/code>\u53ef\u4ee5\u751f\u6210\u6761\u5f62\u56fe\uff0c\u8fd9\u4e9b\u56fe\u8868\u80fd\u591f\u6709\u6548\u5730\u5c55\u793a\u7edf\u8ba1\u7ed3\u679c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u7f3a\u5931\u7684\u6570\u636e\u4ee5\u4fbf\u8fdb\u884c\u7edf\u8ba1\uff1f<\/strong><br \/>\u5728\u8fdb\u884c\u7edf\u8ba1\u4e4b\u524d\uff0c\u5904\u7406\u7f3a\u5931\u6570\u636e\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u53ef\u4ee5\u4f7f\u7528<code>pandas<\/code>\u4e2d\u7684<code>dropna()<\/code>\u65b9\u6cd5\u6765\u5220\u9664\u7f3a\u5931\u503c\uff0c\u6216\u8005\u4f7f\u7528<code>fillna()<\/code>\u65b9\u6cd5\u586b\u8865\u8fd9\u4e9b\u7f3a\u5931\u503c\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u7528\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u6216\u7279\u5b9a\u503c\u66ff\u6362\u7f3a\u5931\u6570\u636e\uff0c\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u7edf\u8ba1\u7ed3\u679c\u7684\u51c6\u786e\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u7edf\u8ba1\u8f93\u51fa\u7ed3\u679c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3001\u5e93\u51fd\u6570\u4ee5\u53ca\u81ea\u5b9a\u4e49\u51fd\u6570\u7b49\u3002\u4ee5\u4e0b\u662f\u51e0\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\uff1a\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":1182619,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1182611"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1182611"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1182611\/revisions"}],"predecessor-version":[{"id":1182622,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1182611\/revisions\/1182622"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1182619"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1182611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1182611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1182611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}