{"id":3573,"date":"2025-07-19T09:08:35","date_gmt":"2025-07-19T01:08:35","guid":{"rendered":"http:\/\/viplao.com\/?p=3573"},"modified":"2025-07-19T09:08:37","modified_gmt":"2025-07-19T01:08:37","slug":"%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e","status":"publish","type":"post","link":"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/","title":{"rendered":"\u3010PYTHON10\u5e74\u7ecf\u9a8c\u603b\u7ed3\u3011\u7b2c\u4e8c\u8bfe \u7535\u5546\u5e73\u53f0\u9500\u552e\u6570\u636e\u5206\u6790\u5b9e\u8df5\u5206\u89e3 \u2013 \u5e38\u7528\u6570\u636e\u6e05\u6d17\u6848\u4f8b"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_71 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u6587\u7ae0\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#1_%E5%A4%84%E7%90%86%E7%BC%BA%E5%A4%B1%E5%80%BC\" title=\"1. \u5904\u7406\u7f3a\u5931\u503c\">1. \u5904\u7406\u7f3a\u5931\u503c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#2_%E5%88%A0%E9%99%A4%E9%87%8D%E5%A4%8D%E8%AE%B0%E5%BD%95\" title=\"2. \u5220\u9664\u91cd\u590d\u8bb0\u5f55\">2. \u5220\u9664\u91cd\u590d\u8bb0\u5f55<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#3_%E6%A0%87%E5%87%86%E5%8C%96%E6%97%A5%E6%9C%9F%E6%A0%BC%E5%BC%8F\" title=\"3. \u6807\u51c6\u5316\u65e5\u671f\u683c\u5f0f\">3. \u6807\u51c6\u5316\u65e5\u671f\u683c\u5f0f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#4_%E7%BB%9F%E4%B8%80%E5%8D%95%E4%BD%8D\" title=\"4. \u7edf\u4e00\u5355\u4f4d\">4. \u7edf\u4e00\u5355\u4f4d<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#5_%E5%A4%84%E7%90%86%E5%BC%82%E5%B8%B8%E5%80%BC\" title=\"5. \u5904\u7406\u5f02\u5e38\u503c\">5. \u5904\u7406\u5f02\u5e38\u503c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#6_%E8%A7%84%E8%8C%83%E6%96%87%E6%9C%AC%E6%A0%BC%E5%BC%8F\" title=\"6. \u89c4\u8303\u6587\u672c\u683c\u5f0f\">6. \u89c4\u8303\u6587\u672c\u683c\u5f0f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#7_%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E9%AA%8C%E8%AF%81\" title=\"7. \u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\">7. \u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#8_%E7%B1%BB%E5%88%AB%E4%B8%80%E8%87%B4%E6%80%A7\" title=\"8. \u7c7b\u522b\u4e00\u81f4\u6027\">8. \u7c7b\u522b\u4e00\u81f4\u6027<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#9_%E5%9C%B0%E5%9D%80%E6%A0%87%E5%87%86%E5%8C%96\" title=\"9. \u5730\u5740\u6807\u51c6\u5316\">9. \u5730\u5740\u6807\u51c6\u5316<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#10_%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2\" title=\"10. \u6570\u636e\u7c7b\u578b\u8f6c\u6362\">10. \u6570\u636e\u7c7b\u578b\u8f6c\u6362<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#11_%E5%8E%BB%E9%99%A4%E5%99%AA%E5%A3%B0\" title=\"11. \u53bb\u9664\u566a\u58f0\">11. \u53bb\u9664\u566a\u58f0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#12_%E6%95%B0%E6%8D%AE%E5%90%88%E5%B9%B6\" title=\"12. \u6570\u636e\u5408\u5e76\">12. \u6570\u636e\u5408\u5e76<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#13_%E8%BD%AC%E6%8D%A2%E7%BC%96%E7%A0%81\" title=\"13. \u8f6c\u6362\u7f16\u7801\">13. \u8f6c\u6362\u7f16\u7801<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#14_%E7%BC%BA%E5%A4%B1%E5%80%BC%E6%A0%87%E8%AE%B0\" title=\"14. \u7f3a\u5931\u503c\u6807\u8bb0\">14. \u7f3a\u5931\u503c\u6807\u8bb0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#15_%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%95%BF%E5%BA%A6%E9%99%90%E5%88%B6\" title=\"15. \u5b57\u7b26\u4e32\u957f\u5ea6\u9650\u5236\">15. \u5b57\u7b26\u4e32\u957f\u5ea6\u9650\u5236<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#16_%E6%97%B6%E9%97%B4%E5%BA%8F%E5%88%97%E8%B0%83%E6%95%B4\" title=\"16. \u65f6\u95f4\u5e8f\u5217\u8c03\u6574\">16. \u65f6\u95f4\u5e8f\u5217\u8c03\u6574<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#17_%E5%A4%96%E9%94%AE%E7%BA%A6%E6%9D%9F\" title=\"17. \u5916\u952e\u7ea6\u675f\">17. \u5916\u952e\u7ea6\u675f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#18_%E5%BC%82%E5%B8%B8%E6%A3%80%E6%B5%8B%E7%AE%97%E6%B3%95\" title=\"18. \u5f02\u5e38\u68c0\u6d4b\u7b97\u6cd5\">18. \u5f02\u5e38\u68c0\u6d4b\u7b97\u6cd5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#19_%E6%89%B9%E9%87%8F%E6%9B%B4%E6%96%B0%E8%84%9A%E6%9C%AC\" title=\"19. \u6279\u91cf\u66f4\u65b0\u811a\u672c\">19. \u6279\u91cf\u66f4\u65b0\u811a\u672c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/#20_%E6%96%87%E6%A1%A3%E8%AE%B0%E5%BD%95\" title=\"20. \u6587\u6863\u8bb0\u5f55\">20. \u6587\u6863\u8bb0\u5f55<\/a><\/li><\/ul><\/nav><\/div>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_%E5%A4%84%E7%90%86%E7%BC%BA%E5%A4%B1%E5%80%BC\"><\/span>1. \u5904\u7406\u7f3a\u5931\u503c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u4f7f\u7528\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u6216\u4f17\u6570\u586b\u5145\u6570\u503c\u578b\u6570\u636e\u7684\u7f3a\u5931\u503c\uff1b\u4f7f\u7528\u6700\u9891\u7e41\u7c7b\u522b\u586b\u5145\u5206\u7c7b\u6570\u636e\u3002 <strong>\u6848\u4f8b<\/strong>: \u5728\u8ba2\u5355\u8868\u4e2d\uff0c\u67d0\u4e9b\u5ba2\u6237\u7684\u5e74\u9f84\u4fe1\u606f\u7f3a\u5931\uff0c\u53ef\u4ee5\u4f7f\u7528\u6240\u6709\u5ba2\u6237\u5e74\u9f84\u7684\u5e73\u5747\u503c\u6765\u586b\u8865\u8fd9\u4e9b\u7f3a\u5931\u9879\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code><strong>import<\/strong> pandas <strong>as<\/strong> pd\n\n# \u793a\u4f8b\u6570\u636e\ndata = {'customer_id': [1, 2, 3, 4],\n        'age': [25, <strong>None<\/strong>, 30, 22]}\ndf = pd.DataFrame(data)\n\n# \u4f7f\u7528\u5e73\u5747\u503c\u586b\u5145\u7f3a\u5931\u7684\u5e74\u9f84\nmean_age = df['age'].mean()\ndf['age'].fillna(mean_age, inplace=<strong>True<\/strong>)\nprint(df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_%E5%88%A0%E9%99%A4%E9%87%8D%E5%A4%8D%E8%AE%B0%E5%BD%95\"><\/span>2. \u5220\u9664\u91cd\u590d\u8bb0\u5f55<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u5229\u7528pandas\u5e93\u53bb\u9664\u91cd\u590d\u7684\u6570\u636e\u6761\u76ee\u3002 <strong>\u6848\u4f8b<\/strong>: \u68c0\u67e5\u7528\u6237\u6ce8\u518c\u8868\uff0c\u53d1\u73b0\u6709\u591a\u540d\u7528\u6237\u7684\u90ae\u7bb1\u5730\u5740\u5b8c\u5168\u76f8\u540c\uff0c\u5220\u9664\u591a\u4f59\u7684\u8bb0\u5f55\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code># \u793a\u4f8b\u6570\u636e\ndata = {'email': ['user1@example.com', 'user2@example.com', 'user1@example.com'],\n        'name': ['Alice', 'Bob', 'Alice']}\ndf = pd.DataFrame(data)\n\n# \u5220\u9664\u91cd\u590d\u8bb0\u5f55\ndf.drop_duplicates(inplace=<strong>True<\/strong>)\nprint(df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_%E6%A0%87%E5%87%86%E5%8C%96%E6%97%A5%E6%9C%9F%E6%A0%BC%E5%BC%8F\"><\/span>3. \u6807\u51c6\u5316\u65e5\u671f\u683c\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u5c06\u6240\u6709\u7684\u65e5\u671f\u5b57\u6bb5\u8f6c\u6362\u4e3a\u7edf\u4e00\u7684\u6807\u51c6\u683c\u5f0f\uff08\u5982YYYY-MM-DD\uff09\u3002 <strong>\u6848\u4f8b<\/strong>: \u8ba2\u5355\u8868\u4e2d\u7684\u65e5\u671f\u5b57\u6bb5\u683c\u5f0f\u4e0d\u4e00\uff0c\u6709\u4e9b\u662fMM\/DD\/YYYY\uff0c\u6709\u4e9b\u662fDD\/MM\/YYYY\uff0c\u5c06\u5176\u5168\u90e8\u8f6c\u6362\u4e3aYYYY-MM-DD\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code><strong>from<\/strong> datetime <strong>import<\/strong> datetime\n\n# \u793a\u4f8b\u6570\u636e\ndata = {'order_date': ['01\/15\/2020', '15\/01\/2020', '02\/20\/2020']}\ndf = pd.DataFrame(data)\n\n# \u5b9a\u4e49\u4e24\u79cd\u53ef\u80fd\u7684\u65e5\u671f\u683c\u5f0f\ndate_formats = ['%m\/%d\/%Y', '%d\/%m\/%Y']\n\n# \u89e3\u6790\u5e76\u6807\u51c6\u5316\u65e5\u671f\n<strong>def<\/strong> <strong>parse_date<\/strong>(date_str):\n    <strong>for<\/strong> fmt <strong>in<\/strong> date_formats:\n        <strong>try<\/strong>:\n            <strong>return<\/strong> datetime.strptime(date_str, fmt).strftime('%Y-%m-%d')\n        <strong>except<\/strong> ValueError:\n            <strong>pass<\/strong>\n    <strong>raise<\/strong> ValueError(f\"Date format not recognized: {date_str}\")\n\ndf['order_date'] = df['order_date'].apply(parse_date)\nprint(df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_%E7%BB%9F%E4%B8%80%E5%8D%95%E4%BD%8D\"><\/span>4. \u7edf\u4e00\u5355\u4f4d<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u786e\u4fdd\u6240\u6709\u5ea6\u91cf\u5355\u4f4d\u4e00\u81f4\uff0c\u4f8b\u5982\u91cd\u91cf\u3001\u4ef7\u683c\u7b49\u3002 <strong>\u6848\u4f8b<\/strong>: \u5546\u54c1\u8868\u4e2d\uff0c\u6709\u4e9b\u5546\u54c1\u7684\u4ef7\u683c\u662f\u4ee5\u5143\u4e3a\u5355\u4f4d\uff0c\u6709\u4e9b\u662f\u4ee5\u89d2\u4e3a\u5355\u4f4d\uff0c\u5c06\u5b83\u4eec\u90fd\u8f6c\u6362\u4e3a\u5143\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code># \u793a\u4f8b\u6570\u636e\ndata = {'product_id': [1, 2],\n        'price': [250, 25]}\ndf = pd.DataFrame(data)\n\n# \u5047\u8bbe\u7b2c\u4e8c\u884c\u7684\u4ef7\u683c\u662f\u4ee5\u89d2\u4e3a\u5355\u4f4d\uff0c\u8f6c\u6362\u4e3a\u5143\ndf.loc[df.index[1], 'price'] \/= 10\nprint(df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_%E5%A4%84%E7%90%86%E5%BC%82%E5%B8%B8%E5%80%BC\"><\/span>5. \u5904\u7406\u5f02\u5e38\u503c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u4f7f\u7528\u7bb1\u7ebf\u56fe\u6216\u5176\u4ed6\u7edf\u8ba1\u65b9\u6cd5\u8bc6\u522b\u5e76\u5904\u7406\u5f02\u5e38\u503c\u3002 <strong>\u6848\u4f8b<\/strong>: \u53d1\u73b0\u67d0\u4e2a\u4ea7\u54c1\u7684\u5355\u4ef7\u9ad8\u8fbe\u6570\u5341\u4e07\uff0c\u660e\u663e\u662f\u4e00\u4e2a\u9519\u8bef\u8f93\u5165\uff0c\u9700\u8981\u8fdb\u4e00\u6b65\u8c03\u67e5\u539f\u56e0\u540e\u51b3\u5b9a\u5982\u4f55\u5904\u7406\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code><strong>import<\/strong> matplotlib.pyplot <strong>as<\/strong> plt\n\n# \u793a\u4f8b\u6570\u636e\ndata = {'product_id': [1, 2, 3, 4],\n        'price': [250, 260, 270, 250000]}\ndf = pd.DataFrame(data)\n\n# \u7ed8\u5236\u7bb1\u7ebf\u56fe\u4ee5\u8bc6\u522b\u5f02\u5e38\u503c\nplt.boxplot(df['price'])\nplt.show()\n\n# \u8fc7\u6ee4\u6389\u5f02\u5e38\u503c\nq1 = df['price'].quantile(0.25)\nq3 = df['price'].quantile(0.75)\niqr = q3 - q1\nfiltered_df = df[(df['price'] &gt;= (q1 - 1.5 * iqr)) &amp; (df['price'] &lt;= (q3 + 1.5 * iqr))]\nprint(filtered_df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_%E8%A7%84%E8%8C%83%E6%96%87%E6%9C%AC%E6%A0%BC%E5%BC%8F\"><\/span>6. \u89c4\u8303\u6587\u672c\u683c\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u5bf9\u4e8e\u6587\u672c\u5b57\u6bb5\uff0c\u7edf\u4e00\u5927\u5c0f\u5199\uff0c\u53bb\u9664\u524d\u540e\u7a7a\u683c\u3002 <strong>\u6848\u4f8b<\/strong>: \u7528\u6237\u8bc4\u8bba\u4e2d\u7684\u4ea7\u54c1\u540d\u79f0\u6709\u65f6\u4f1a\u56e0\u4e3a\u5927\u5c0f\u5199\u4e0d\u540c\u800c\u88ab\u89c6\u4e3a\u4e0d\u540c\u7684\u4ea7\u54c1\uff0c\u7edf\u4e00\u6539\u4e3a\u5c0f\u5199\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code># \u793a\u4f8b\u6570\u636e\ndata = {'comment': ['Great Product!', 'great product ', 'PRODUCT IS GOOD']}\ndf = pd.DataFrame(data)\n\n# \u7edf\u4e00\u5c0f\u5199\u5e76\u53bb\u9664\u524d\u540e\u7a7a\u683c\ndf['comment'] = df['comment'].str.lower().str.strip()\nprint(df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7_%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E9%AA%8C%E8%AF%81\"><\/span>7. \u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u7b26\u5408\u9884\u671f\u6a21\u5f0f\u3002 <strong>\u6848\u4f8b<\/strong>: \u9a8c\u8bc1\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u683c\u5f0f\uff0c\u786e\u4fdd\u5176\u7b26\u5408\u6807\u51c6\u7684\u7535\u5b50\u90ae\u4ef6\u683c\u5f0f\u89c4\u5219\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code><strong>import<\/strong> re\n\n# \u793a\u4f8b\u6570\u636e\ndata = {'email': ['user1@example.com', 'invalid-email', 'user2@domain.co.uk']}\ndf = pd.DataFrame(data)\n\n# \u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\u7535\u5b50\u90ae\u4ef6\u683c\u5f0f\nemail_pattern = r'^[\\w\\.-]+@[\\w\\.-]+\\.\\w+$'\n\n<strong>def<\/strong> <strong>is_valid_email<\/strong>(email):\n    <strong>return<\/strong> bool(re.match(email_pattern, email))\n\ndf['is_valid'] = df['email'].apply(is_valid_email)\nprint(df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8_%E7%B1%BB%E5%88%AB%E4%B8%80%E8%87%B4%E6%80%A7\"><\/span>8. \u7c7b\u522b\u4e00\u81f4\u6027<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u786e\u4fdd\u5206\u7c7b\u5b57\u6bb5\u4e2d\u7684\u7c7b\u522b\u540d\u79f0\u4e00\u81f4\u3002 <strong>\u6848\u4f8b<\/strong>: \u5546\u54c1\u5206\u7c7b\u4e2d\u6709\u201c\u624b\u673a\u201d\u3001\u201c\u667a\u80fd\u624b\u673a\u201d\u3001\u201c\u79fb\u52a8\u7535\u8bdd\u201d\uff0c\u5c06\u5b83\u4eec\u7edf\u4e00\u4e3a\u201c\u624b\u673a\u201d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code># \u793a\u4f8b\u6570\u636e\ndata = {'category': ['\u624b\u673a', '\u667a\u80fd\u624b\u673a', '\u79fb\u52a8\u7535\u8bdd', '\u624b\u673a']}\ndf = pd.DataFrame(data)\n\n# \u6620\u5c04\u7c7b\u522b\u540d\u79f0\ncategory_mapping = {'\u667a\u80fd\u624b\u673a': '\u624b\u673a', '\u79fb\u52a8\u7535\u8bdd': '\u624b\u673a'}\ndf['category'] = df['category'].map(category_mapping).fillna(df['category'])\nprint(df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"9_%E5%9C%B0%E5%9D%80%E6%A0%87%E5%87%86%E5%8C%96\"><\/span>9. \u5730\u5740\u6807\u51c6\u5316<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u4f7f\u7528\u5730\u7406\u7f16\u7801\u670d\u52a1\u5c06\u5730\u5740\u8f6c\u6362\u4e3a\u7ecf\u7eac\u5ea6\u5750\u6807\uff0c\u4ee5\u4fbf\u8fdb\u884c\u7a7a\u95f4\u5206\u6790\u3002 <strong>\u6848\u4f8b<\/strong>: \u5c06\u7528\u6237\u914d\u9001\u5730\u5740\u8f6c\u6362\u4e3a\u7ecf\u7eac\u5ea6\uff0c\u7528\u4e8e\u5206\u6790\u54ea\u4e9b\u5730\u533a\u7684\u8d2d\u4e70\u529b\u66f4\u5f3a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code># \u793a\u4f8b\u6570\u636e\ndata = {'address': ['\u4e0a\u6d77\u5e02\u6d66\u4e1c\u65b0\u533a\u4e16\u7eaa\u5927\u9053100\u53f7', '\u5317\u4eac\u5e02\u671d\u9633\u533a\u5efa\u56fd\u95e8\u5916\u5927\u88571\u53f7']}\ndf = pd.DataFrame(data)\n\n# \u4f7f\u7528geopy\u5e93\u83b7\u53d6\u7ecf\u7eac\u5ea6\n<strong>from<\/strong> geopy.geocoders <strong>import<\/strong> Nominatim\n\ngeolocator = Nominatim(user_agent=\"geoapiExercises\")\n\n<strong>def<\/strong> <strong>get_coordinates<\/strong>(address):\n    location = geolocator.geocode(address)\n    <strong>if<\/strong> location:\n        <strong>return<\/strong> (location.latitude, location.longitude)\n    <strong>else<\/strong>:\n        <strong>return<\/strong> <strong>None<\/strong>\n\ndf['coordinates'] = df['address'].apply(get_coordinates)\nprint(df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"10_%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2\"><\/span>10. \u6570\u636e\u7c7b\u578b\u8f6c\u6362<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u786e\u4fdd\u6bcf\u4e2a\u5b57\u6bb5\u5b58\u50a8\u6b63\u786e\u7684\u6570\u636e\u7c7b\u578b\u3002 <strong>\u6848\u4f8b<\/strong>: \u7528\u6237ID\u539f\u672c\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u5b58\u50a8\uff0c\u73b0\u5728\u5e94\u8f6c\u6362\u4e3a\u6574\u6570\u7c7b\u578b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code># \u793a\u4f8b\u6570\u636e\ndata = {'user_id': ['1', '2', '3'], 'name': ['Alice', 'Bob', 'Charlie']}\ndf = pd.DataFrame(data)\n\n# \u8f6c\u6362\u6570\u636e\u7c7b\u578b\ndf['user_id'] = df['user_id'].astype(int)\nprint(df.dtypes)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"11_%E5%8E%BB%E9%99%A4%E5%99%AA%E5%A3%B0\"><\/span>11. \u53bb\u9664\u566a\u58f0<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u79fb\u9664\u65e0\u5173\u7d27\u8981\u7684\u4fe1\u606f\uff0c\u4f8b\u5982HTML\u6807\u7b7e\u3001\u7279\u6b8a\u5b57\u7b26\u7b49\u3002 <strong>\u6848\u4f8b<\/strong>: \u6e05\u6d17\u7528\u6237\u8bc4\u8bba\u65f6\uff0c\u79fb\u9664\u5176\u4e2d\u5305\u542b\u7684HTML\u6807\u7b7e\u548c\u5176\u4ed6\u4e0d\u9700\u8981\u7684\u7b26\u53f7\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code><strong>from<\/strong> bs4 <strong>import<\/strong> BeautifulSoup\n\n# \u793a\u4f8b\u6570\u636e\ndata = {'comment': ['&lt;b&gt;Great&lt;\/b&gt; Product!', 'Product is &lt;br\/&gt;good.', 'Excellent!']}\ndf = pd.DataFrame(data)\n\n# \u4f7f\u7528BeautifulSoup\u53bb\u9664HTML\u6807\u7b7e\n<strong>def<\/strong> <strong>remove_html_tags<\/strong>(text):\n    soup = BeautifulSoup(text, \"html.parser\")\n    <strong>return<\/strong> soup.get_text()\n\ndf['clean_comment'] = df['comment'].apply(remove_html_tags)\nprint(df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"12_%E6%95%B0%E6%8D%AE%E5%90%88%E5%B9%B6\"><\/span>12. \u6570\u636e\u5408\u5e76<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u5408\u5e76\u6765\u81ea\u4e0d\u540c\u6e90\u7684\u6570\u636e\u96c6\uff0c\u786e\u4fdd\u6240\u6709\u76f8\u5173\u4fe1\u606f\u90fd\u5728\u4e00\u4e2a\u8868\u683c\u4e2d\u3002 <strong>\u6848\u4f8b<\/strong>: \u5c06\u5e93\u5b58\u6570\u636e\u8868\u4e0e\u8ba2\u5355\u6570\u636e\u8868\u5408\u5e76\uff0c\u4ee5\u4fbf\u4e86\u89e3\u54ea\u4e9b\u5546\u54c1\u552e\u7f44\u6700\u5feb\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code># \u793a\u4f8b\u6570\u636e\ninventory_data = {'product_id': [1, 2, 3], 'stock': [10, 20, 0]}\norders_data = {'product_id': [1, 2, 1], 'quantity': [1, 2, 1]}\n\ninventory_df = pd.DataFrame(inventory_data)\norders_df = pd.DataFrame(orders_data)\n\n# \u5408\u5e76\u4e24\u4e2a\u6570\u636e\u96c6\nmerged_df = pd.merge(inventory_df, orders_df, on='product_id')\nprint(merged_df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"13_%E8%BD%AC%E6%8D%A2%E7%BC%96%E7%A0%81\"><\/span>13. \u8f6c\u6362\u7f16\u7801<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u5c06\u975eUTF-8\u7f16\u7801\u7684\u6570\u636e\u8f6c\u6362\u4e3aUTF-8\u7f16\u7801\u3002 <strong>\u6848\u4f8b<\/strong>: \u67d0\u4e9bCSV\u6587\u4ef6\u53ef\u80fd\u662fGBK\u7f16\u7801\u7684\uff0c\u9700\u8981\u5148\u8f6c\u7801\u518d\u8bfb\u53d6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code># \u793a\u4f8b\u6570\u636e\uff1a\u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a'sales_data.csv'\u7684\u6587\u4ef6\uff0c\u5b83\u662fGBK\u7f16\u7801\u7684\n# sales_data.csv \u5185\u5bb9\uff1a\n# product_id,name,price\n# 1,\u624b\u673a,250\n# 2,\u7535\u8111,3000\n\n# \u8bfb\u53d6\u5e76\u8f6c\u6362\u7f16\u7801\nsales_df = pd.read_csv('sales_data.csv', encoding='gbk')\nprint(sales_df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"14_%E7%BC%BA%E5%A4%B1%E5%80%BC%E6%A0%87%E8%AE%B0\"><\/span>14. \u7f3a\u5931\u503c\u6807\u8bb0<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u660e\u786e\u6807\u8bb0\u7f3a\u5931\u503c\uff0c\u907f\u514d\u5728\u540e\u7eed\u5206\u6790\u4e2d\u88ab\u8bef\u8ba4\u4e3a\u5b9e\u9645\u6570\u636e\u3002 <strong>\u6848\u4f8b<\/strong>: \u5728\u6570\u636e\u96c6\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u5217\uff0c\u4e13\u95e8\u7528\u6765\u6807\u8bc6\u90a3\u4e9b\u539f\u59cb\u6570\u636e\u4e2d\u5b58\u5728\u7f3a\u5931\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code># \u793a\u4f8b\u6570\u636e\ndata = {'customer_id': [1, 2, 3, 4],\n        'age': [25, <strong>None<\/strong>, 30, 22]}\ndf = pd.DataFrame(data)\n\n# \u6dfb\u52a0\u6807\u8bb0\u5217\ndf['age_missing'] = df['age'].isnull()\nprint(df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"15_%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%95%BF%E5%BA%A6%E9%99%90%E5%88%B6\"><\/span>15. \u5b57\u7b26\u4e32\u957f\u5ea6\u9650\u5236<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u5bf9\u8fc7\u957f\u7684\u5b57\u7b26\u4e32\u8fdb\u884c\u622a\u65ad\u6216\u8005\u6e05\u7406\u3002 <strong>\u6848\u4f8b<\/strong>: \u6709\u4e9b\u7528\u6237\u7684\u5907\u6ce8\u680f\u975e\u5e38\u5197\u957f\uff0c\u5bfc\u81f4\u6570\u636e\u5e93\u5b57\u6bb5\u6ea2\u51fa\uff0c\u9700\u8981\u622a\u65ad\u5230\u4e00\u5b9a\u957f\u5ea6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code># \u793a\u4f8b\u6570\u636e\ndata = {'remark': ['This is a very long remark that needs to be truncated.',\n                   'Short remark',\n                   'Another long remark that should be shortened.']}\ndf = pd.DataFrame(data)\n\n# \u622a\u65ad\u5b57\u7b26\u4e32\nmax_length = 20\ndf['short_remark'] = df['remark'].str[:max_length]\nprint(df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"16_%E6%97%B6%E9%97%B4%E5%BA%8F%E5%88%97%E8%B0%83%E6%95%B4\"><\/span>16. \u65f6\u95f4\u5e8f\u5217\u8c03\u6574<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u786e\u4fdd\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u6309\u987a\u5e8f\u6392\u5217\uff0c\u5e76\u4e14\u6ca1\u6709\u8df3\u8fc7\u7684\u70b9\u3002 <strong>\u6848\u4f8b<\/strong>: \u9500\u552e\u6570\u636e\u7684\u65f6\u95f4\u6233\u53ef\u80fd\u4e71\u5e8f\uff0c\u9700\u8981\u91cd\u65b0\u6392\u5e8f\u5e76\u4e14\u8865\u5168\u7f3a\u5931\u7684\u65f6\u95f4\u70b9\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code><strong>import<\/strong> numpy <strong>as<\/strong> np\n\n# \u793a\u4f8b\u6570\u636e\ndata = {'timestamp': ['2020-01-01', '2020-01-03', '2020-01-02'],\n        'sales': [100, 200, 150]}\ndf = pd.DataFrame(data)\n\n# \u8f6c\u6362\u4e3adatetime\u7c7b\u578b\ndf['timestamp'] = pd.to_datetime(df['timestamp'])\n\n# \u6392\u5e8f\ndf.sort_values(by='timestamp', inplace=<strong>True<\/strong>)\n\n# \u8865\u5145\u7f3a\u5931\u7684\u65f6\u95f4\u6233\nall_dates = pd.date_range(start=df['timestamp'].min(), end=df['timestamp'].max())\ndf.set_index('timestamp', inplace=<strong>True<\/strong>)\ndf = df.reindex(all_dates, fill_value=np.nan)\ndf.reset_index(inplace=<strong>True<\/strong>)\ndf.rename(columns={'index': 'timestamp'}, inplace=<strong>True<\/strong>)\nprint(df)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"17_%E5%A4%96%E9%94%AE%E7%BA%A6%E6%9D%9F\"><\/span>17. \u5916\u952e\u7ea6\u675f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u5728\u5173\u7cfb\u578b\u6570\u636e\u5e93\u4e2d\u8bbe\u7f6e\u5916\u952e\u7ea6\u675f\uff0c\u9632\u6b62\u5b64\u7acb\u8bb0\u5f55\u7684\u5b58\u5728\u3002 <strong>\u6848\u4f8b<\/strong>: \u786e\u4fdd\u6bcf\u4e2a\u8ba2\u5355\u90fd\u6709\u5bf9\u5e94\u7684\u7528\u6237ID\uff0c\u5982\u679c\u627e\u4e0d\u5230\u5339\u914d\u7684\u7528\u6237\uff0c\u5219\u8be5\u8ba2\u5355\u65e0\u6548\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code># \u793a\u4f8b\u6570\u636e\nusers_data = {'user_id': [1, 2, 3], 'name': ['Alice', 'Bob', 'Charlie']}\norders_data = {'order_id': [1, 2, 3], 'user_id': [1, 2, 4]}  # \u6ce8\u610f\u6700\u540e\u4e00\u4e2auser_id\u4e0d\u5b58\u5728\n\nusers_df = pd.DataFrame(users_data)\norders_df = pd.DataFrame(orders_data)\n\n# \u5408\u5e76\u6570\u636e\u96c6\u5e76\u68c0\u67e5\u5b64\u7acb\u8bb0\u5f55\nmerged_df = pd.merge(orders_df, users_df, on='user_id', how='left')\nisolated_orders = merged_df[merged_df['name'].isna()]\nprint(\"Isolated Orders:\")\nprint(isolated_orders)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"18_%E5%BC%82%E5%B8%B8%E6%A3%80%E6%B5%8B%E7%AE%97%E6%B3%95\"><\/span>18. \u5f02\u5e38\u68c0\u6d4b\u7b97\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u5e94\u7528\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u81ea\u52a8\u68c0\u6d4b\u6f5c\u5728\u7684\u5f02\u5e38\u503c\u3002 <strong>\u6848\u4f8b<\/strong>: \u4f7f\u7528\u805a\u7c7b\u7b97\u6cd5\u627e\u51fa\u9500\u552e\u989d\u5206\u5e03\u4e2d\u7684\u79bb\u7fa4\u70b9\uff0c\u786e\u5b9a\u662f\u5426\u5b58\u5728\u6b3a\u8bc8\u884c\u4e3a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code><strong>from<\/strong> sklearn.cluster <strong>import<\/strong> DBSCAN\n\n# \u793a\u4f8b\u6570\u636e\ndata = {'store_id': [1, 2, 3, 4, 5],\n        'sales': [100, 120, 110, 500, 115]}\ndf = pd.DataFrame(data)\n\n# \u4f7f\u7528DBSCAN\u7b97\u6cd5\u68c0\u6d4b\u5f02\u5e38\u503c\nmodel = DBSCAN(eps=50, min_samples=2)\ndf['cluster'] = model.fit_predict(df[['sales']])\noutliers = df[df['cluster'] == -1]\nprint(\"Outliers:\")\nprint(outliers)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"19_%E6%89%B9%E9%87%8F%E6%9B%B4%E6%96%B0%E8%84%9A%E6%9C%AC\"><\/span>19. \u6279\u91cf\u66f4\u65b0\u811a\u672c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u521b\u5efa\u81ea\u52a8\u5316\u811a\u672c\u6765\u6279\u91cf\u6267\u884c\u6e05\u6d17\u4efb\u52a1\u3002 <strong>\u6848\u4f8b<\/strong>: \u6bcf\u5929\u665a\u4e0a\u81ea\u52a8\u8fd0\u884cPython\u811a\u672c\uff0c\u6e05\u9664\u65b0\u5bfc\u5165\u6570\u636e\u4e2d\u7684\u810f\u6570\u636e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code># \u5047\u8bbe\u6211\u4eec\u6bcf\u5929\u4eceCSV\u6587\u4ef6\u5bfc\u5165\u65b0\u7684\u6570\u636e\n# \u65b0\u6570\u636e\u6587\u4ef6\u540d\u4e3a'daily_sales_YYYYMMDD.csv'\n# \u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u811a\u672c\u6846\u67b6\n\n<strong>import<\/strong> os\n<strong>from<\/strong> datetime <strong>import<\/strong> datetime\n\n<strong>def<\/strong> <strong>clean_data<\/strong>(file_path):\n    # \u52a0\u8f7d\u6570\u636e\n    df = pd.read_csv(file_path)\n    \n    # \u5904\u7406\u7f3a\u5931\u503c\n    mean_price = df['price'].mean()\n    df['price'].fillna(mean_price, inplace=<strong>True<\/strong>)\n    \n    # \u5220\u9664\u91cd\u590d\u8bb0\u5f55\n    df.drop_duplicates(inplace=<strong>True<\/strong>)\n    \n    # \u6807\u51c6\u5316\u65e5\u671f\u683c\u5f0f\n    <strong>def<\/strong> <strong>parse_date<\/strong>(date_str):\n        <strong>try<\/strong>:\n            <strong>return<\/strong> datetime.strptime(date_str, '%m\/%d\/%Y').strftime('%Y-%m-%d')\n        <strong>except<\/strong> ValueError:\n            <strong>return<\/strong> <strong>None<\/strong>\n    \n    df['order_date'] = df['order_date'].apply(parse_date)\n    \n    # \u5176\u4ed6\u6e05\u6d17\u6b65\u9aa4...\n    \n    # \u4fdd\u5b58\u6e05\u7406\u540e\u7684\u6570\u636e\n    cleaned_file_path = file_path.replace('.csv', '_cleaned.csv')\n    df.to_csv(cleaned_file_path, index=<strong>False<\/strong>)\n\n# \u83b7\u53d6\u5f53\u5929\u7684\u6587\u4ef6\u540d\ntoday = datetime.now().strftime('%Y%m%d')\nfile_name = f'daily_sales_{today}.csv'\n\n<strong>if<\/strong> os.path.exists(file_name):\n    clean_data(file_name)\n<strong>else<\/strong>:\n    print(f\"File {file_name} does not exist.\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"20_%E6%96%87%E6%A1%A3%E8%AE%B0%E5%BD%95\"><\/span>20. \u6587\u6863\u8bb0\u5f55<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5b9e\u8df5<\/strong>: \u8bb0\u5f55\u6bcf\u6b21\u6e05\u6d17\u64cd\u4f5c\u7684\u8fc7\u7a0b\u548c\u7ed3\u679c\uff0c\u65b9\u4fbf\u65e5\u540e\u5ba1\u8ba1\u548c\u91cd\u73b0\u3002 <strong>\u6848\u4f8b<\/strong>: \u4fdd\u5b58\u6bcf\u6b21\u6570\u636e\u6e05\u6d17\u524d\u540e\u7684\u5bf9\u6bd4\u62a5\u544a\uff0c\u5305\u62ec\u5177\u4f53\u7684\u64cd\u4f5c\u7ec6\u8282\u548c\u5f71\u54cd\u8303\u56f4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Python\u6df1\u8272\u7248\u672c<code><strong>import<\/strong> logging\n\n# \u8bbe\u7f6e\u65e5\u5fd7\u8bb0\u5f55\u5668\nlogging.basicConfig(filename='data_cleaning.log', level=logging.INFO,\n                    format='%(asctime)s - %(levelname)s - %(message)s')\n\n# \u65e5\u5fd7\u8bb0\u5f55\u51fd\u6570\n<strong>def<\/strong> <strong>log_cleaning_operation<\/strong>(operation_description, before, after):\n    logging.info(f\"Operation: {operation_description}\")\n    logging.info(f\"Before:\\n{before.head()}\\nAfter:\\n{after.head()}\")\n\n# \u793a\u4f8b\u6570\u636e\ndata = {'customer_id': [1, 2, 3, 4],\n        'age': [25, <strong>None<\/strong>, 30, 22]}\ndf = pd.DataFrame(data)\n\n# \u8bb0\u5f55\u521d\u59cb\u72b6\u6001\nlog_cleaning_operation(\"Initial Data\", df.copy(), df)\n\n# \u5904\u7406\u7f3a\u5931\u503c\nmean_age = df['age'].mean()\ndf['age'].fillna(mean_age, inplace=<strong>True<\/strong>)\n\n# \u8bb0\u5f55\u5904\u7406\u7f3a\u5931\u503c\u540e\u7684\u72b6\u6001\nlog_cleaning_operation(\"Fill Missing Age Values\", df.copy(), df)\n\n# \u5220\u9664\u91cd\u590d\u8bb0\u5f55\ndf.drop_duplicates(inplace=<strong>True<\/strong>)\n\n# \u8bb0\u5f55\u5220\u9664\u91cd\u590d\u8bb0\u5f55\u540e\u7684\u72b6\u6001\nlog_cleaning_operation(\"Remove Duplicate Records\", df.copy(), df)\n\n# \u8f93\u51fa\u6700\u7ec8\u72b6\u6001\nprint(df)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. \u5904\u7406\u7f3a\u5931\u503c \u5b9e\u8df5: \u4f7f\u7528\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u6216\u4f17\u6570\u586b\u5145\u6570\u503c\u578b\u6570\u636e\u7684\u7f3a\u5931\u503c\uff1b\u4f7f\u7528\u6700\u9891\u7e41\u7c7b\u522b\u586b\u5145\u5206\u7c7b\u6570\u636e\u3002&hellip; <a href=\"http:\/\/viplao.com\/index.php\/2025\/07\/19\/%e3%80%90python10%e5%b9%b4%e7%bb%8f%e9%aa%8c%e6%80%bb%e7%bb%93%e3%80%91%e7%ac%ac%e4%ba%8c%e8%af%be-%e7%94%b5%e5%95%86%e5%b9%b3%e5%8f%b0%e9%94%80%e5%94%ae%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e5%ae%9e\/\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">\u3010PYTHON10\u5e74\u7ecf\u9a8c\u603b\u7ed3\u3011\u7b2c\u4e8c\u8bfe \u7535\u5546\u5e73\u53f0\u9500\u552e\u6570\u636e\u5206\u6790\u5b9e\u8df5\u5206\u89e3 \u2013 \u5e38\u7528\u6570\u636e\u6e05\u6d17\u6848\u4f8b<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[28],"views":942,"_links":{"self":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/3573"}],"collection":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/comments?post=3573"}],"version-history":[{"count":1,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/3573\/revisions"}],"predecessor-version":[{"id":3574,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/3573\/revisions\/3574"}],"wp:attachment":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/media?parent=3573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/categories?post=3573"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/tags?post=3573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}