{"id":1097780,"date":"2025-01-08T15:15:06","date_gmt":"2025-01-08T07:15:06","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1097780.html"},"modified":"2025-01-08T15:15:08","modified_gmt":"2025-01-08T07:15:08","slug":"python%e5%a6%82%e4%bd%95%e6%9f%a5%e6%89%be%e6%95%b0%e6%8d%ae%e7%9a%84%e6%9c%80%e5%a4%a7%e5%92%8c%e6%9c%80%e5%b0%8f-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1097780.html","title":{"rendered":"python\u5982\u4f55\u67e5\u627e\u6570\u636e\u7684\u6700\u5927\u548c\u6700\u5c0f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24212354\/98012865-5ca0-4619-8ea9-6c6c1a878b7e.webp\" alt=\"python\u5982\u4f55\u67e5\u627e\u6570\u636e\u7684\u6700\u5927\u548c\u6700\u5c0f\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u67e5\u627e\u6570\u636e\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u51fd\u6570max()\u548cmin()\u3001\u901a\u8fc7\u8fed\u4ee3\u548c\u6bd4\u8f83\u6765\u624b\u52a8\u67e5\u627e\u3001\u4f7f\u7528NumPy\u5e93\u7b49\u65b9\u6cd5\u3002\u4f7f\u7528\u5185\u7f6e\u51fd\u6570max()\u548cmin()\u662f\u6700\u5e38\u7528\u4e14\u9ad8\u6548\u7684\u65b9\u6cd5\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u5bf9\u5176\u4e2d\u7684\u5185\u7f6e\u51fd\u6570\u65b9\u6cd5\u8fdb\u884c\u8be6\u7ec6\u63cf\u8ff0\u3002<\/strong><\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528\u5185\u7f6e\u51fd\u6570max()\u548cmin()\u662f\u6700\u5e38\u7528\u4e14\u9ad8\u6548\u7684\u65b9\u6cd5<\/strong>\u3002\u901a\u8fc7\u8c03\u7528max()\u51fd\u6570\u53ef\u4ee5\u5f97\u5230\u6570\u636e\u4e2d\u7684\u6700\u5927\u503c\uff0c\u800cmin()\u51fd\u6570\u53ef\u4ee5\u5f97\u5230\u6570\u636e\u4e2d\u7684\u6700\u5c0f\u503c\u3002\u8fd9\u4e24\u4e2a\u51fd\u6570\u90fd\u53ef\u4ee5\u4f5c\u7528\u4e8e\u5217\u8868\u3001\u5143\u7ec4\u3001\u96c6\u5408\u7b49\u53ef\u8fed\u4ee3\u5bf9\u8c61\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [3, 5, 1, 2, 9, 7]<\/p>\n<p>max_value = max(data)<\/p>\n<p>min_value = min(data)<\/p>\n<p>print(f&quot;Maximum value: {max_value}, Minimum value: {min_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e00\u3001\u5185\u7f6e\u51fd\u6570max()\u548cmin()<\/h3>\n<\/p>\n<p><p>Python\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u975e\u5e38\u65b9\u4fbf\u7684\u5185\u7f6e\u51fd\u6570max()\u548cmin()\uff0c\u7528\u4e8e\u67e5\u627e\u53ef\u8fed\u4ee3\u5bf9\u8c61\u4e2d\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002\u5b83\u4eec\u7684\u57fa\u672c\u7528\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u57fa\u672c\u7528\u6cd5<\/h4>\n<\/p>\n<p><p>\u5185\u7f6e\u51fd\u6570max()\u548cmin()\u53ef\u4ee5\u76f4\u63a5\u4f5c\u7528\u4e8e\u5217\u8868\u3001\u5143\u7ec4\u3001\u96c6\u5408\u7b49\u53ef\u8fed\u4ee3\u5bf9\u8c61\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [3, 5, 1, 2, 9, 7]<\/p>\n<p>max_value = max(data)<\/p>\n<p>min_value = min(data)<\/p>\n<p>print(f&quot;Maximum value: {max_value}, Minimum value: {min_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cmax()\u51fd\u6570\u8fd4\u56de\u6570\u636e\u4e2d\u7684\u6700\u5927\u503c9\uff0c\u800cmin()\u51fd\u6570\u8fd4\u56de\u6570\u636e\u4e2d\u7684\u6700\u5c0f\u503c1\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f5c\u7528\u4e8e\u5b57\u7b26\u4e32<\/h4>\n<\/p>\n<p><p>max()\u548cmin()\u51fd\u6570\u8fd8\u53ef\u4ee5\u4f5c\u7528\u4e8e\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u5b57\u5178\u5e8f\u6700\u5927\u7684\u548c\u6700\u5c0f\u7684\u5b57\u7b26\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">string = &quot;hello&quot;<\/p>\n<p>max_char = max(string)<\/p>\n<p>min_char = min(string)<\/p>\n<p>print(f&quot;Maximum character: {max_char}, Minimum character: {min_char}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cmax()\u51fd\u6570\u8fd4\u56de\u5b57\u5178\u5e8f\u6700\u5927\u7684\u5b57\u7b26&#39;o&#39;\uff0cmin()\u51fd\u6570\u8fd4\u56de\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b57\u7b26&#39;e&#39;\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u4f5c\u7528\u4e8e\u4e8c\u7ef4\u5217\u8868<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u4e8c\u7ef4\u5217\u8868\uff0cmax()\u548cmin()\u51fd\u6570\u53ef\u4ee5\u901a\u8fc7key\u53c2\u6570\u6307\u5b9a\u6bd4\u8f83\u7684\u5173\u952e\u5b57\u3002\u4f8b\u5982\uff0c\u67e5\u627e\u4e8c\u7ef4\u5217\u8868\u4e2d\u6bcf\u4e2a\u5b50\u5217\u8868\u7684\u6700\u5927\u548c\u6700\u5c0f\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">matrix = [[3, 5], [1, 2], [9, 7]]<\/p>\n<p>max_row = max(matrix, key=lambda x: max(x))<\/p>\n<p>min_row = min(matrix, key=lambda x: min(x))<\/p>\n<p>print(f&quot;Row with maximum value: {max_row}, Row with minimum value: {min_row}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cmax()\u51fd\u6570\u8fd4\u56de\u6700\u5927\u503c\u6240\u5728\u7684\u5b50\u5217\u8868[9, 7]\uff0cmin()\u51fd\u6570\u8fd4\u56de\u6700\u5c0f\u503c\u6240\u5728\u7684\u5b50\u5217\u8868[1, 2]\u3002<\/p>\n<\/p>\n<p><h4>4\u3001\u4f7f\u7528key\u53c2\u6570\u81ea\u5b9a\u4e49\u6bd4\u8f83\u89c4\u5219<\/h4>\n<\/p>\n<p><p>max()\u548cmin()\u51fd\u6570\u90fd\u652f\u6301key\u53c2\u6570\uff0c\u5141\u8bb8\u6211\u4eec\u81ea\u5b9a\u4e49\u6bd4\u8f83\u89c4\u5219\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u6570\u636e\u7684\u7edd\u5bf9\u503c\u67e5\u627e\u6700\u5927\u548c\u6700\u5c0f\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [-3, 5, -1, 2, -9, 7]<\/p>\n<p>max_value = max(data, key=abs)<\/p>\n<p>min_value = min(data, key=abs)<\/p>\n<p>print(f&quot;Maximum value by absolute: {max_value}, Minimum value by absolute: {min_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cmax()\u51fd\u6570\u6839\u636e\u7edd\u5bf9\u503c\u67e5\u627e\u6700\u5927\u503c\u8fd4\u56de-9\uff0c\u800cmin()\u51fd\u6570\u8fd4\u56de\u7edd\u5bf9\u503c\u6700\u5c0f\u7684\u503c-1\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u624b\u52a8\u8fed\u4ee3\u548c\u6bd4\u8f83<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528\u5185\u7f6e\u51fd\u6570max()\u548cmin()\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7\u624b\u52a8\u8fed\u4ee3\u548c\u6bd4\u8f83\u6765\u67e5\u627e\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002\u8fd9\u79cd\u65b9\u6cd5\u867d\u7136\u4ee3\u7801\u8f83\u591a\uff0c\u4f46\u53ef\u4ee5\u66f4\u597d\u5730\u7406\u89e3\u67e5\u627e\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u57fa\u672c\u8fed\u4ee3\u67e5\u627e<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u904d\u5386\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u4f7f\u7528\u6761\u4ef6\u5224\u65ad\u6765\u66f4\u65b0\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [3, 5, 1, 2, 9, 7]<\/p>\n<p>max_value = data[0]<\/p>\n<p>min_value = data[0]<\/p>\n<p>for value in data:<\/p>\n<p>    if value &gt; max_value:<\/p>\n<p>        max_value = value<\/p>\n<p>    if value &lt; min_value:<\/p>\n<p>        min_value = value<\/p>\n<p>print(f&quot;Maximum value: {max_value}, Minimum value: {min_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u521d\u59cb\u5316\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u4e3a\u5217\u8868\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u7136\u540e\u904d\u5386\u5217\u8868\uff0c\u6839\u636e\u6761\u4ef6\u5224\u65ad\u66f4\u65b0\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528\u81ea\u5b9a\u4e49\u6bd4\u8f83\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u81ea\u5b9a\u4e49\u6bd4\u8f83\u51fd\u6570\uff0c\u4f20\u9012\u7ed9\u67e5\u627e\u51fd\u6570\u4ee5\u5b9e\u73b0\u7279\u5b9a\u7684\u6bd4\u8f83\u89c4\u5219\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def custom_max(data, key):<\/p>\n<p>    max_value = data[0]<\/p>\n<p>    for value in data:<\/p>\n<p>        if key(value) &gt; key(max_value):<\/p>\n<p>            max_value = value<\/p>\n<p>    return max_value<\/p>\n<p>def custom_min(data, key):<\/p>\n<p>    min_value = data[0]<\/p>\n<p>    for value in data:<\/p>\n<p>        if key(value) &lt; key(min_value):<\/p>\n<p>            min_value = value<\/p>\n<p>    return min_value<\/p>\n<p>data = [-3, 5, -1, 2, -9, 7]<\/p>\n<p>max_value = custom_max(data, abs)<\/p>\n<p>min_value = custom_min(data, abs)<\/p>\n<p>print(f&quot;Custom maximum by absolute: {max_value}, Custom minimum by absolute: {min_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86custom_max\u548ccustom_min\u51fd\u6570\uff0c\u901a\u8fc7\u4f20\u9012\u81ea\u5b9a\u4e49\u6bd4\u8f83\u51fd\u6570key\u53c2\u6570\uff0c\u5b9e\u73b0\u4e86\u6839\u636e\u7edd\u5bf9\u503c\u67e5\u627e\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528NumPy\u5e93<\/h3>\n<\/p>\n<p><p>NumPy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u9ad8\u6548\u7684\u6570\u7ec4\u64cd\u4f5c\u51fd\u6570\u3002\u4f7f\u7528NumPy\u53ef\u4ee5\u65b9\u4fbf\u5730\u67e5\u627e\u6570\u7ec4\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5NumPy<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5NumPy\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u67e5\u627e\u6570\u7ec4\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c<\/h4>\n<\/p>\n<p><p>NumPy\u63d0\u4f9b\u4e86numpy.max()\u548cnumpy.min()\u51fd\u6570\uff0c\u7528\u4e8e\u67e5\u627e\u6570\u7ec4\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>data = np.array([3, 5, 1, 2, 9, 7])<\/p>\n<p>max_value = np.max(data)<\/p>\n<p>min_value = np.min(data)<\/p>\n<p>print(f&quot;NumPy maximum value: {max_value}, NumPy minimum value: {min_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cnp.max()\u51fd\u6570\u8fd4\u56de\u6570\u7ec4\u7684\u6700\u5927\u503c9\uff0cnp.min()\u51fd\u6570\u8fd4\u56de\u6570\u7ec4\u7684\u6700\u5c0f\u503c1\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u67e5\u627e\u591a\u7ef4\u6570\u7ec4\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u591a\u7ef4\u6570\u7ec4\uff0cNumPy\u53ef\u4ee5\u6cbf\u6307\u5b9a\u8f74\u67e5\u627e\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>matrix = np.array([[3, 5], [1, 2], [9, 7]])<\/p>\n<p>max_value = np.max(matrix, axis=0)<\/p>\n<p>min_value = np.min(matrix, axis=1)<\/p>\n<p>print(f&quot;NumPy maximum values by axis 0: {max_value}&quot;)<\/p>\n<p>print(f&quot;NumPy minimum values by axis 1: {min_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cnp.max(matrix, axis=0)\u8fd4\u56de\u6bcf\u5217\u7684\u6700\u5927\u503c[9, 7]\uff0cnp.min(matrix, axis=1)\u8fd4\u56de\u6bcf\u884c\u7684\u6700\u5c0f\u503c[3, 1, 7]\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001pandas\u5e93<\/h3>\n<\/p>\n<p><p>pandas\u662f\u53e6\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u5e93\uff0c\u7279\u522b\u9002\u7528\u4e8e\u8868\u683c\u6570\u636e\u7684\u5904\u7406\u3002\u4f7f\u7528pandas\u53ef\u4ee5\u65b9\u4fbf\u5730\u67e5\u627eDataFrame\u548cSeries\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5pandas<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5pandas\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u67e5\u627eSeries\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c<\/h4>\n<\/p>\n<p><p>pandas\u63d0\u4f9b\u4e86Series.max()\u548cSeries.min()\u51fd\u6570\uff0c\u7528\u4e8e\u67e5\u627eSeries\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = pd.Series([3, 5, 1, 2, 9, 7])<\/p>\n<p>max_value = data.max()<\/p>\n<p>min_value = data.min()<\/p>\n<p>print(f&quot;pandas Series maximum value: {max_value}, pandas Series minimum value: {min_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cdata.max()\u51fd\u6570\u8fd4\u56deSeries\u7684\u6700\u5927\u503c9\uff0cdata.min()\u51fd\u6570\u8fd4\u56deSeries\u7684\u6700\u5c0f\u503c1\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u67e5\u627eDataFrame\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c<\/h4>\n<\/p>\n<p><p>pandas\u8fd8\u63d0\u4f9b\u4e86DataFrame.max()\u548cDataFrame.min()\u51fd\u6570\uff0c\u7528\u4e8e\u67e5\u627eDataFrame\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = pd.DataFrame({<\/p>\n<p>    &#39;A&#39;: [3, 5, 1],<\/p>\n<p>    &#39;B&#39;: [2, 9, 7]<\/p>\n<p>})<\/p>\n<p>max_value = data.max()<\/p>\n<p>min_value = data.min()<\/p>\n<p>print(f&quot;pandas DataFrame maximum values: {max_value}&quot;)<\/p>\n<p>print(f&quot;pandas DataFrame minimum values: {min_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cdata.max()\u51fd\u6570\u8fd4\u56de\u6bcf\u5217\u7684\u6700\u5927\u503c\uff0cdata.min()\u51fd\u6570\u8fd4\u56de\u6bcf\u5217\u7684\u6700\u5c0f\u503c\u3002<\/p>\n<\/p>\n<p><h4>4\u3001\u6cbf\u6307\u5b9a\u8f74\u67e5\u627e\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8eDataFrame\uff0cpandas\u53ef\u4ee5\u6cbf\u6307\u5b9a\u8f74\u67e5\u627e\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = pd.DataFrame({<\/p>\n<p>    &#39;A&#39;: [3, 5, 1],<\/p>\n<p>    &#39;B&#39;: [2, 9, 7]<\/p>\n<p>})<\/p>\n<p>max_value_by_row = data.max(axis=1)<\/p>\n<p>min_value_by_column = data.min(axis=0)<\/p>\n<p>print(f&quot;pandas DataFrame maximum values by row: {max_value_by_row}&quot;)<\/p>\n<p>print(f&quot;pandas DataFrame minimum values by column: {min_value_by_column}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cdata.max(axis=1)\u8fd4\u56de\u6bcf\u884c\u7684\u6700\u5927\u503c\uff0cdata.min(axis=0)\u8fd4\u56de\u6bcf\u5217\u7684\u6700\u5c0f\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528\u7edf\u8ba1\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u4e00\u4e9b\u7edf\u8ba1\u5206\u6790\u3002Python\u7684\u7edf\u8ba1\u5e93\u63d0\u4f9b\u4e86\u8bb8\u591a\u7edf\u8ba1\u51fd\u6570\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u67e5\u627e\u6570\u636e\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5\u7edf\u8ba1\u5e93<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u5b89\u88c5Python\u7684\u7edf\u8ba1\u5e93\uff0c\u4f8b\u5982SciPy\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install scipy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528SciPy\u67e5\u627e\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c<\/h4>\n<\/p>\n<p><p>SciPy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u7edf\u8ba1\u51fd\u6570\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528SciPy\u67e5\u627e\u6570\u636e\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from scipy import stats<\/p>\n<p>data = [3, 5, 1, 2, 9, 7]<\/p>\n<p>max_value = stats.describe(data).max<\/p>\n<p>min_value = stats.describe(data).min<\/p>\n<p>print(f&quot;SciPy maximum value: {max_value}, SciPy minimum value: {min_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cstats.describe()\u51fd\u6570\u8fd4\u56de\u6570\u636e\u7684\u7edf\u8ba1\u63cf\u8ff0\uff0c\u5176\u4e2d\u5305\u542b\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u67e5\u627e\u6570\u636e\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u51fd\u6570max()\u548cmin()\u3001\u901a\u8fc7\u624b\u52a8\u8fed\u4ee3\u548c\u6bd4\u8f83\u3001\u4f7f\u7528NumPy\u5e93\u3001\u4f7f\u7528pandas\u5e93\u4ee5\u53ca\u4f7f\u7528\u7edf\u8ba1\u51fd\u6570\u7b49\u3002<strong>\u4f7f\u7528\u5185\u7f6e\u51fd\u6570max()\u548cmin()\u662f\u6700\u5e38\u7528\u4e14\u9ad8\u6548\u7684\u65b9\u6cd5<\/strong>\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u60c5\u51b5\u3002\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\u548c\u9700\u6c42\uff0c\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528NumPy\u548cpandas\u5e93\uff0c\u5b83\u4eec\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u80fd\u529b\u3002\u901a\u8fc7\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u573a\u666f\u4e2d\u7075\u6d3b\u5730\u67e5\u627e\u6570\u636e\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5feb\u901f\u627e\u5230\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u4f7f\u7528\u5185\u7f6e\u7684<code>max()<\/code>\u548c<code>min()<\/code>\u51fd\u6570\u53ef\u4ee5\u8f7b\u677e\u627e\u5230\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a\u5217\u8868<code>data = [1, 2, 3, 4, 5]<\/code>\uff0c\u53ef\u4ee5\u4f7f\u7528<code>max(data)<\/code>\u6765\u83b7\u5f97\u6700\u5927\u503c5\uff0c\u4f7f\u7528<code>min(data)<\/code>\u83b7\u5f97\u6700\u5c0f\u503c1\u3002\u8fd9\u4e24\u4e2a\u51fd\u6570\u4e0d\u4ec5\u9002\u7528\u4e8e\u5217\u8868\uff0c\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5176\u4ed6\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff0c\u5982\u5143\u7ec4\u548c\u96c6\u5408\u3002<\/p>\n<p><strong>\u5728\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u65f6\uff0c\u5982\u4f55\u9ad8\u6548\u67e5\u627e\u6700\u5927\u548c\u6700\u5c0f\u503c\uff1f<\/strong><br \/>\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u96c6\uff0c\u4f7f\u7528<code>max()<\/code>\u548c<code>min()<\/code>\u51fd\u6570\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6027\u80fd\u95ee\u9898\u3002\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528NumPy\u5e93\u7684<code>np.max()<\/code>\u548c<code>np.min()<\/code>\u51fd\u6570\u6765\u63d0\u9ad8\u6548\u7387\u3002\u8fd9\u4e9b\u51fd\u6570\u7ecf\u8fc7\u4f18\u5316\uff0c\u7279\u522b\u9002\u5408\u5904\u7406\u5927\u578b\u6570\u7ec4\uff0c\u80fd\u591f\u663e\u8457\u51cf\u5c11\u8ba1\u7b97\u65f6\u95f4\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u67e5\u627e\u5b57\u5178\u4e2d\u6700\u5927\u548c\u6700\u5c0f\u503c\uff1f<\/strong><br \/>\u5728\u5b57\u5178\u4e2d\u67e5\u627e\u6700\u5927\u548c\u6700\u5c0f\u503c\u901a\u5e38\u6d89\u53ca\u952e\u6216\u503c\u7684\u9009\u62e9\u3002\u5982\u679c\u60f3\u6839\u636e\u503c\u67e5\u627e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>max()<\/code>\u548c<code>min()<\/code>\u51fd\u6570\u4e0e<code>key<\/code>\u53c2\u6570\u7ed3\u5408\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a\u5b57\u5178<code>data = {&#39;a&#39;: 1, &#39;b&#39;: 5, &#39;c&#39;: 3}<\/code>\uff0c\u60f3\u8981\u627e\u5230\u6700\u5927\u503c\u7684\u952e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>max(data, key=data.get)<\/code>\uff0c\u5b83\u5c06\u8fd4\u56de&#39;c&#39;\uff0c\u56e0\u4e3a\u5bf9\u5e94\u7684\u503c3\u662f\u6700\u5927\u7684\u3002\u540c\u6837\uff0c\u4f7f\u7528<code>min(data, key=data.get)<\/code>\u53ef\u4ee5\u627e\u5230\u6700\u5c0f\u503c\u7684\u952e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u67e5\u627e\u6570\u636e\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u51fd\u6570max()\u548cmin()\u3001\u901a\u8fc7\u8fed\u4ee3\u548c\u6bd4\u8f83\u6765\u624b\u52a8\u67e5\u627e\u3001\u4f7f\u7528 [&hellip;]","protected":false},"author":3,"featured_media":1097787,"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\/1097780"}],"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=1097780"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1097780\/revisions"}],"predecessor-version":[{"id":1097790,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1097780\/revisions\/1097790"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1097787"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1097780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1097780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1097780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}