{"id":49603,"date":"2024-12-03T14:25:00","date_gmt":"2024-12-03T06:25:00","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49603\/"},"modified":"2024-12-03T14:25:00","modified_gmt":"2024-12-03T06:25:00","slug":"%e5%a6%82%e4%bd%95%e7%bb%99-pandas-dataframe-%e4%b8%ad%e6%8c%87%e5%ae%9a%e5%88%97%e7%9a%84%e5%80%bc%e5%89%8d%e5%90%8e%e6%b7%bb%e5%8a%a0%e7%89%b9%e5%ae%9a%e5%ad%97%e7%ac%a6%e4%b8%b2%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49603\/","title":{"rendered":"\u5982\u4f55\u7ed9 Pandas DataFrame \u4e2d\u6307\u5b9a\u5217\u7684\u503c\u524d\u540e\u6dfb\u52a0\u7279\u5b9a\u5b57\u7b26\u4e32\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u7ed9 Pandas DataFrame \u4e2d\u6307\u5b9a\u5217\u7684\u503c\u524d\u540e\u6dfb\u52a0\u7279\u5b9a\u5b57\u7b26\u4e32\uff1f<\/h1>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300a\u5982\u4f55\u7ed9 Pandas DataFrame \u4e2d\u6307\u5b9a\u5217\u7684\u503c\u524d\u540e\u6dfb\u52a0\u7279\u5b9a\u5b57\u7b26\u4e32\uff1f\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241029\/173016220167202e193c007.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u7ed9 Pandas DataFrame \u4e2d\u6307\u5b9a\u5217\u7684\u503c\u524d\u540e\u6dfb\u52a0\u7279\u5b9a\u5b57\u7b26\u4e32\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u7ed9 Pandas DataFrame \u4e2d\u6307\u5b9a\u5217\u7684\u503c\u524d\u540e\u6dfb\u52a0\u7279\u5b9a\u5b57\u7b26\u4e32\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4fee\u6539 dataframe \u4e2d\u6307\u5b9a\u5217\u7684\u503c<\/strong><\/p>\n<p>\u5047\u5982\u6709\u5982\u4e0b dataframe\uff1a<\/p>\n<pre>a   b\n0   cm1 b1-name xxxx\n1   cm2 name yyyy\n2   cm3 b3-name name zzzz<\/pre>\n<p>\u9700\u8981\u5728 b \u5217\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u524d\u540e\u6dfb\u52a0 &#8220;!a!&#8221;\uff0c\u5f97\u5230\u4ee5\u4e0b\u7ed3\u679c\uff1a<\/p>\n<pre>a   b\n0   cm1 !a!b1-name xxxx!a!\n1   cm2 !a!name yyyy!a!\n2   cm3 !a!b3-name name zzzz!a!<\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<pre>import pandas as pd\n\n# \u521b\u5efa DataFrame\ndf = pd.DataFrame({'a': ['cm1', 'cm2', 'cm3'],\n                   'b': ['b1-name xxxx', 'name yyyy', 'b3-name name zzzz']})\n\n# \u4fee\u6539 b \u5217\u7684\u503c\nfor i in range(len(df['b'])):\n    df['b'][i] = '!A!' + ' '.join(df['b'][i].split()).replace(' ','!A!') + '!A!'<\/pre>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u5982\u4f55\u7ed9 Pandas DataFrame \u4e2d\u6307\u5b9a\u5217\u7684\u503c\u524d\u540e\u6dfb\u52a0\u7279\u5b9a\u5b57\u7b26\u4e32\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u7ed9 Pandas DataFrame \u4e2d\u6307\u5b9a\u5217\u7684\u503c\u524d\u540e\u6dfb\u52a0\u7279\u5b9a\u5b57\u7b26\u4e32\uff1f \u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300a\u5982\u4f55\u7ed9 Pandas DataFrame \u4e2d\u6307\u5b9a\u5217\u7684\u503c\u524d\u540e\u6dfb\u52a0\u7279\u5b9a\u5b57\u7b26\u4e32\uff1f\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 \u4fee\u6539 dataframe \u4e2d\u6307\u5b9a\u5217\u7684\u503c \u5047\u5982\u6709\u5982\u4e0b dataframe\uff1a a b 0 cm1 b1-name xxxx 1 cm2 name yyyy 2 cm3 b3-name name zzzz \u9700\u8981\u5728 b \u5217\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u524d\u540e\u6dfb\u52a0 &#8220;!a!&#8221;\uff0c\u5f97\u5230\u4ee5\u4e0b\u7ed3\u679c\uff1a a b 0 cm1 !a!b1-name xxxx!a! 1 cm2 !a!name yyyy!a! 2 cm3 !a!b3-name name zzzz!a! \u89e3\u51b3\u65b9\u6cd5\uff1a import pandas as pd # \u521b\u5efa DataFrame [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-49603","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=49603"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49603\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}