{"id":1052026,"date":"2024-12-31T14:21:26","date_gmt":"2024-12-31T06:21:26","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1052026.html"},"modified":"2024-12-31T14:21:28","modified_gmt":"2024-12-31T06:21:28","slug":"python%e5%a6%82%e4%bd%95%e5%90%8c%e6%97%b6%e5%87%ba%e7%8e%b0%e4%b8%a4%e4%b8%aa%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1052026.html","title":{"rendered":"python\u5982\u4f55\u540c\u65f6\u51fa\u73b0\u4e24\u4e2a\u8868"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/a5b7ca46-dab0-4607-af23-cc45f045c22d.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u540c\u65f6\u51fa\u73b0\u4e24\u4e2a\u8868\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528Python\u540c\u65f6\u663e\u793a\u4e24\u4e2a\u8868<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u540c\u65f6\u663e\u793a\u4e24\u4e2a\u8868\u7684\u9700\u6c42\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c<strong>\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528pandas\u5e93\u3001Jupyter Notebook\u7684\u663e\u793a\u529f\u80fd\u3001\u4ee5\u53camatplotlib\u5e93<\/strong>\u3002\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u793a\u4f8b\u4ee3\u7801\u6765\u5c55\u793a\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528Pandas\u5e93<\/h3>\n<\/p>\n<p><p>Pandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u636e\u7ed3\u6784\u548c\u5de5\u5177\u6765\u64cd\u4f5c\u8868\u683c\u6570\u636e\u3002<strong>\u901a\u8fc7pandas\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u521b\u5efa\u548c\u663e\u793a\u591a\u4e2a\u8868\u683c<\/strong>\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528pandas\u5e93\u6765\u540c\u65f6\u663e\u793a\u4e24\u4e2a\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e00\u4e2a\u8868<\/strong><\/h2>\n<p>data1 = {<\/p>\n<p>    &#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>    &#39;Age&#39;: [25, 30, 35]<\/p>\n<p>}<\/p>\n<p>df1 = pd.DataFrame(data1)<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e8c\u4e2a\u8868<\/strong><\/h2>\n<p>data2 = {<\/p>\n<p>    &#39;Product&#39;: [&#39;Apples&#39;, &#39;Bananas&#39;, &#39;Cherries&#39;],<\/p>\n<p>    &#39;Quantity&#39;: [10, 20, 30]<\/p>\n<p>}<\/p>\n<p>df2 = pd.DataFrame(data2)<\/p>\n<h2><strong>\u663e\u793a\u4e24\u4e2a\u8868<\/strong><\/h2>\n<p>print(&quot;Table 1:&quot;)<\/p>\n<p>print(df1)<\/p>\n<p>print(&quot;\\nTable 2:&quot;)<\/p>\n<p>print(df2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u63a7\u5236\u53f0\u4e2d\u540c\u65f6\u770b\u5230\u4e24\u4e2a\u8868\u7684\u5185\u5bb9\u3002<strong>Pandas\u7684DataFrame\u5bf9\u8c61\u63d0\u4f9b\u4e86\u4e00\u79cd\u975e\u5e38\u65b9\u4fbf\u7684\u65b9\u5f0f\u6765\u7ba1\u7406\u548c\u663e\u793a\u8868\u683c\u6570\u636e<\/strong>\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Jupyter Notebook<\/h3>\n<\/p>\n<p><p>Jupyter Notebook\u662f\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684\u4ea4\u4e92\u5f0f\u8ba1\u7b97\u73af\u5883\uff0c\u7279\u522b\u9002\u5408\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u4efb\u52a1\u3002<strong>\u5728Jupyter Notebook\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528display\u51fd\u6570\u6765\u540c\u65f6\u663e\u793a\u591a\u4e2a\u8868\u683c<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from IPython.display import display<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e00\u4e2a\u8868<\/strong><\/h2>\n<p>data1 = {<\/p>\n<p>    &#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>    &#39;Age&#39;: [25, 30, 35]<\/p>\n<p>}<\/p>\n<p>df1 = pd.DataFrame(data1)<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e8c\u4e2a\u8868<\/strong><\/h2>\n<p>data2 = {<\/p>\n<p>    &#39;Product&#39;: [&#39;Apples&#39;, &#39;Bananas&#39;, &#39;Cherries&#39;],<\/p>\n<p>    &#39;Quantity&#39;: [10, 20, 30]<\/p>\n<p>}<\/p>\n<p>df2 = pd.DataFrame(data2)<\/p>\n<h2><strong>\u540c\u65f6\u663e\u793a\u4e24\u4e2a\u8868<\/strong><\/h2>\n<p>display(df1)<\/p>\n<p>display(df2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Jupyter Notebook\u4e2d\uff0cdisplay\u51fd\u6570\u53ef\u4ee5\u540c\u65f6\u663e\u793a\u591a\u4e2aDataFrame\u5bf9\u8c61\uff0c<strong>\u8fd9\u6837\u6211\u4eec\u53ef\u4ee5\u5728\u4e00\u4e2a\u5355\u5143\u683c\u4e2d\u770b\u5230\u591a\u4e2a\u8868\u683c\u7684\u5185\u5bb9<\/strong>\u3002\u8fd9\u5bf9\u4e8e\u6570\u636e\u5206\u6790\u548c\u62a5\u544a\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528Matplotlib\u5e93<\/h3>\n<\/p>\n<p><p>Matplotlib\u662f\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u7ed8\u56fe\u5e93\uff0c\u4e3b\u8981\u7528\u4e8e\u521b\u5efa\u9759\u6001\u3001\u52a8\u753b\u548c\u4ea4\u4e92\u5f0f\u53ef\u89c6\u5316\u3002<strong>\u867d\u7136Matplotlib\u4e3b\u8981\u7528\u4e8e\u7ed8\u56fe\uff0c\u4f46\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u540c\u65f6\u663e\u793a\u591a\u4e2a\u8868\u683c<\/strong>\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528matplotlib\u6765\u663e\u793a\u4e24\u4e2a\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e00\u4e2a\u8868<\/strong><\/h2>\n<p>data1 = {<\/p>\n<p>    &#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>    &#39;Age&#39;: [25, 30, 35]<\/p>\n<p>}<\/p>\n<p>df1 = pd.DataFrame(data1)<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e8c\u4e2a\u8868<\/strong><\/h2>\n<p>data2 = {<\/p>\n<p>    &#39;Product&#39;: [&#39;Apples&#39;, &#39;Bananas&#39;, &#39;Cherries&#39;],<\/p>\n<p>    &#39;Quantity&#39;: [10, 20, 30]<\/p>\n<p>}<\/p>\n<p>df2 = pd.DataFrame(data2)<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u5f62\u548c\u8f74<\/strong><\/h2>\n<p>fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4))<\/p>\n<h2><strong>\u5728\u7b2c\u4e00\u4e2a\u8f74\u4e0a\u663e\u793a\u7b2c\u4e00\u4e2a\u8868<\/strong><\/h2>\n<p>ax1.axis(&#39;tight&#39;)<\/p>\n<p>ax1.axis(&#39;off&#39;)<\/p>\n<p>ax1.table(cellText=df1.values, colLabels=df1.columns, cellLoc=&#39;center&#39;, loc=&#39;center&#39;)<\/p>\n<h2><strong>\u5728\u7b2c\u4e8c\u4e2a\u8f74\u4e0a\u663e\u793a\u7b2c\u4e8c\u4e2a\u8868<\/strong><\/h2>\n<p>ax2.axis(&#39;tight&#39;)<\/p>\n<p>ax2.axis(&#39;off&#39;)<\/p>\n<p>ax2.table(cellText=df2.values, colLabels=df2.columns, cellLoc=&#39;center&#39;, loc=&#39;center&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\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\u7528\u4e86Matplotlib\u7684table\u51fd\u6570\u6765\u521b\u5efa\u548c\u663e\u793a\u8868\u683c\u3002<strong>\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e24\u4e2a\u8f74\u7684\u56fe\u5f62\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u540c\u4e00\u4e2a\u56fe\u5f62\u7a97\u53e3\u4e2d\u663e\u793a\u4e24\u4e2a\u8868\u683c<\/strong>\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528Dash\u5e93<\/h3>\n<\/p>\n<p><p>Dash\u662f\u4e00\u4e2a\u7528\u4e8e\u6784\u5efa\u52a8\u6001Web\u5e94\u7528\u7a0b\u5e8f\u7684Python\u6846\u67b6\uff0c\u7279\u522b\u9002\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u3002<strong>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Dash\u6765\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u8868\u683c\u7684Web\u5e94\u7528\u7a0b\u5e8f<\/strong>\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528Dash\u6765\u540c\u65f6\u663e\u793a\u4e24\u4e2a\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import dash<\/p>\n<p>import dash_table<\/p>\n<p>import pandas as pd<\/p>\n<p>import dash_html_components as html<\/p>\n<h2><strong>\u521b\u5efaDash\u5e94\u7528\u7a0b\u5e8f<\/strong><\/h2>\n<p>app = dash.Dash(__name__)<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e00\u4e2a\u8868<\/strong><\/h2>\n<p>data1 = {<\/p>\n<p>    &#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>    &#39;Age&#39;: [25, 30, 35]<\/p>\n<p>}<\/p>\n<p>df1 = pd.DataFrame(data1)<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e8c\u4e2a\u8868<\/strong><\/h2>\n<p>data2 = {<\/p>\n<p>    &#39;Product&#39;: [&#39;Apples&#39;, &#39;Bananas&#39;, &#39;Cherries&#39;],<\/p>\n<p>    &#39;Quantity&#39;: [10, 20, 30]<\/p>\n<p>}<\/p>\n<p>df2 = pd.DataFrame(data2)<\/p>\n<h2><strong>\u5b9a\u4e49\u5e94\u7528\u7a0b\u5e8f\u5e03\u5c40<\/strong><\/h2>\n<p>app.layout = html.Div([<\/p>\n<p>    dash_table.DataTable(<\/p>\n<p>        id=&#39;table1&#39;,<\/p>\n<p>        columns=[{&#39;name&#39;: i, &#39;id&#39;: i} for i in df1.columns],<\/p>\n<p>        data=df1.to_dict(&#39;records&#39;)<\/p>\n<p>    ),<\/p>\n<p>    html.Br(),<\/p>\n<p>    dash_table.DataTable(<\/p>\n<p>        id=&#39;table2&#39;,<\/p>\n<p>        columns=[{&#39;name&#39;: i, &#39;id&#39;: i} for i in df2.columns],<\/p>\n<p>        data=df2.to_dict(&#39;records&#39;)<\/p>\n<p>    )<\/p>\n<p>])<\/p>\n<h2><strong>\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f<\/strong><\/h2>\n<p>if __name__ == &#39;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&#39;:<\/p>\n<p>    app.run_server(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e24\u4e2a\u8868\u683c\u7684Dash\u5e94\u7528\u7a0b\u5e8f\u3002<strong>Dash\u63d0\u4f9b\u4e86\u4e00\u79cd\u975e\u5e38\u7075\u6d3b\u548c\u5f3a\u5927\u7684\u65b9\u5f0f\u6765\u6784\u5efa\u4ea4\u4e92\u5f0fWeb\u5e94\u7528\u7a0b\u5e8f<\/strong>\uff0c\u7279\u522b\u9002\u5408\u9700\u8981\u5728Web\u6d4f\u89c8\u5668\u4e2d\u663e\u793a\u591a\u4e2a\u8868\u683c\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528Plotly\u5e93<\/h3>\n<\/p>\n<p><p>Plotly\u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u4ea4\u4e92\u5f0f\u56fe\u8868\u548c\u53ef\u89c6\u5316\u7684\u5e93\u3002<strong>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Plotly\u6765\u521b\u5efa\u548c\u663e\u793a\u591a\u4e2a\u8868\u683c<\/strong>\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528Plotly\u6765\u540c\u65f6\u663e\u793a\u4e24\u4e2a\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import plotly.graph_objects as go<\/p>\n<p>import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e00\u4e2a\u8868<\/strong><\/h2>\n<p>data1 = {<\/p>\n<p>    &#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>    &#39;Age&#39;: [25, 30, 35]<\/p>\n<p>}<\/p>\n<p>df1 = pd.DataFrame(data1)<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e8c\u4e2a\u8868<\/strong><\/h2>\n<p>data2 = {<\/p>\n<p>    &#39;Product&#39;: [&#39;Apples&#39;, &#39;Bananas&#39;, &#39;Cherries&#39;],<\/p>\n<p>    &#39;Quantity&#39;: [10, 20, 30]<\/p>\n<p>}<\/p>\n<p>df2 = pd.DataFrame(data2)<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e00\u4e2a\u8868\u683c\u56fe\u5f62<\/strong><\/h2>\n<p>fig1 = go.Figure(data=[go.Table(<\/p>\n<p>    header=dict(values=list(df1.columns),<\/p>\n<p>                fill_color=&#39;paleturquoise&#39;,<\/p>\n<p>                align=&#39;left&#39;),<\/p>\n<p>    cells=dict(values=[df1.Name, df1.Age],<\/p>\n<p>               fill_color=&#39;lavender&#39;,<\/p>\n<p>               align=&#39;left&#39;))<\/p>\n<p>])<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e8c\u4e2a\u8868\u683c\u56fe\u5f62<\/strong><\/h2>\n<p>fig2 = go.Figure(data=[go.Table(<\/p>\n<p>    header=dict(values=list(df2.columns),<\/p>\n<p>                fill_color=&#39;paleturquoise&#39;,<\/p>\n<p>                align=&#39;left&#39;),<\/p>\n<p>    cells=dict(values=[df2.Product, df2.Quantity],<\/p>\n<p>               fill_color=&#39;lavender&#39;,<\/p>\n<p>               align=&#39;left&#39;))<\/p>\n<p>])<\/p>\n<h2><strong>\u663e\u793a\u4e24\u4e2a\u56fe\u5f62<\/strong><\/h2>\n<p>fig1.show()<\/p>\n<p>fig2.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Plotly\u6765\u521b\u5efa\u548c\u663e\u793a\u4e24\u4e2a\u8868\u683c\u3002<strong>Plotly\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u4ea4\u4e92\u529f\u80fd\uff0c\u4f7f\u5f97\u6211\u4eec\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u4e0e\u56fe\u8868\u548c\u8868\u683c\u8fdb\u884c\u4ea4\u4e92<\/strong>\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528ipywidgets\u5e93<\/h3>\n<\/p>\n<p><p>ipywidgets\u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u4ea4\u4e92\u5f0f\u5c0f\u90e8\u4ef6\u7684\u5e93\uff0c\u7279\u522b\u9002\u5408\u5728Jupyter Notebook\u4e2d\u4f7f\u7528\u3002<strong>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528ipywidgets\u6765\u540c\u65f6\u663e\u793a\u591a\u4e2a\u8868\u683c<\/strong>\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528ipywidgets\u6765\u540c\u65f6\u663e\u793a\u4e24\u4e2a\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import ipywidgets as widgets<\/p>\n<p>import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e00\u4e2a\u8868<\/strong><\/h2>\n<p>data1 = {<\/p>\n<p>    &#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>    &#39;Age&#39;: [25, 30, 35]<\/p>\n<p>}<\/p>\n<p>df1 = pd.DataFrame(data1)<\/p>\n<h2><strong>\u521b\u5efa\u7b2c\u4e8c\u4e2a\u8868<\/strong><\/h2>\n<p>data2 = {<\/p>\n<p>    &#39;Product&#39;: [&#39;Apples&#39;, &#39;Bananas&#39;, &#39;Cherries&#39;],<\/p>\n<p>    &#39;Quantity&#39;: [10, 20, 30]<\/p>\n<p>}<\/p>\n<p>df2 = pd.DataFrame(data2)<\/p>\n<h2><strong>\u521b\u5efa\u4e24\u4e2a\u8868\u683c\u5c0f\u90e8\u4ef6<\/strong><\/h2>\n<p>table1 = widgets.Output()<\/p>\n<p>table2 = widgets.Output()<\/p>\n<p>with table1:<\/p>\n<p>    display(df1)<\/p>\n<p>with table2:<\/p>\n<p>    display(df2)<\/p>\n<h2><strong>\u663e\u793a\u4e24\u4e2a\u8868\u683c\u5c0f\u90e8\u4ef6<\/strong><\/h2>\n<p>widgets.VBox([table1, table2])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528ipywidgets\u6765\u521b\u5efa\u548c\u663e\u793a\u4e24\u4e2a\u8868\u683c\u5c0f\u90e8\u4ef6\u3002<strong>ipywidgets\u63d0\u4f9b\u4e86\u4e00\u79cd\u975e\u5e38\u76f4\u89c2\u548c\u7b80\u4fbf\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u4ea4\u4e92\u5f0f\u5c0f\u90e8\u4ef6\uff0c\u7279\u522b\u9002\u5408\u5728Jupyter Notebook\u4e2d\u4f7f\u7528<\/strong>\u3002<\/p>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u5728Python\u4e2d\u540c\u65f6\u663e\u793a\u4e24\u4e2a\u8868\u3002<strong>\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u4f18\u52bf\u548c\u9002\u7528\u573a\u666f<\/strong>\u3002Pandas\u9002\u5408\u5904\u7406\u548c\u663e\u793a\u8868\u683c\u6570\u636e\uff0cJupyter Notebook\u63d0\u4f9b\u4e86\u76f4\u89c2\u7684\u4ea4\u4e92\u73af\u5883\uff0cMatplotlib\u9002\u5408\u521b\u5efa\u9759\u6001\u548c\u4ea4\u4e92\u5f0f\u53ef\u89c6\u5316\uff0cDash\u548cPlotly\u9002\u5408\u6784\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\u548c\u4ea4\u4e92\u5f0f\u56fe\u8868\uff0c\u800cipywidgets\u9002\u5408\u5728Jupyter Notebook\u4e2d\u521b\u5efa\u4ea4\u4e92\u5f0f\u5c0f\u90e8\u4ef6\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u9002\u5408\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u548c\u6570\u636e\u5c55\u793a\u6548\u679c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\uff0c\u5982\u4f55\u540c\u65f6\u663e\u793a\u4e24\u4e2a\u8868\u7684\u6570\u636e\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pandas<\/code>\u5e93\u6765\u5904\u7406\u548c\u663e\u793a\u8868\u683c\u6570\u636e\u3002\u901a\u8fc7\u521b\u5efa\u4e24\u4e2a<code>DataFrame<\/code>\uff0c\u7136\u540e\u4f7f\u7528<code>print()<\/code>\u51fd\u6570\u6216<code>display()<\/code>\u51fd\u6570\uff08\u5728Jupyter Notebook\u4e2d\uff09\u6765\u540c\u65f6\u663e\u793a\u5b83\u4eec\u3002\u5982\u679c\u5e0c\u671b\u66f4\u7f8e\u89c2\u7684\u663e\u793a\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528<code>matplotlib<\/code>\u6216<code>seaborn<\/code>\u5e93\u8fdb\u884c\u53ef\u89c6\u5316\u3002<\/p>\n<p><strong>\u6709\u4ec0\u4e48\u65b9\u6cd5\u53ef\u4ee5\u5c06\u4e24\u4e2a\u8868\u683c\u5408\u5e76\u5728\u4e00\u8d77\u663e\u793a\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>pandas<\/code>\u7684<code>concat()<\/code>\u6216<code>merge()<\/code>\u51fd\u6570\u6765\u5408\u5e76\u4e24\u4e2a\u8868\u683c\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5728\u884c\u6216\u5217\u65b9\u5411\u4e0a\u5c06\u8868\u683c\u5408\u5e76\uff0c\u4fbf\u4e8e\u8fdb\u884c\u5bf9\u6bd4\u548c\u5206\u6790\u3002\u4f8b\u5982\uff0c<code>pd.concat([df1, df2], axis=0)<\/code>\u53ef\u4ee5\u5c06\u4e24\u4e2a\u8868\u683c\u5728\u884c\u4e0a\u5408\u5e76\uff0c\u800c<code>pd.merge(df1, df2, on=&#39;key&#39;)<\/code>\u53ef\u4ee5\u901a\u8fc7\u7279\u5b9a\u7684\u5217\u8fdb\u884c\u5408\u5e76\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u5728\u540c\u4e00\u4e2a\u56fe\u5f62\u4e2d\u540c\u65f6\u7ed8\u5236\u4e24\u4e2a\u8868\u7684\u6570\u636e\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528<code>matplotlib<\/code>\u5e93\u5728\u540c\u4e00\u4e2a\u56fe\u5f62\u4e2d\u7ed8\u5236\u4e24\u4e2a\u8868\u7684\u6570\u636e\u3002\u901a\u8fc7\u521b\u5efa\u591a\u4e2a\u5b50\u56fe\uff0c\u6216\u8005\u5728\u540c\u4e00\u4e2a\u5750\u6807\u8f74\u4e0a\u7ed8\u5236\u4e0d\u540c\u7684\u6570\u636e\u96c6\uff0c\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002<code>plt.plot()<\/code>\u51fd\u6570\u53ef\u4ee5\u7528\u6765\u7ed8\u5236\u7ebf\u56fe\uff0c\u800c<code>plt.bar()<\/code>\u53ef\u4ee5\u7528\u6765\u7ed8\u5236\u67f1\u72b6\u56fe\uff0c\u4ece\u800c\u6e05\u6670\u5730\u5c55\u793a\u4e24\u4e2a\u8868\u7684\u6570\u636e\u5bf9\u6bd4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u540c\u65f6\u663e\u793a\u4e24\u4e2a\u8868 \u5728Python\u4e2d\uff0c\u540c\u65f6\u663e\u793a\u4e24\u4e2a\u8868\u7684\u9700\u6c42\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":1052039,"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\/1052026"}],"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=1052026"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1052026\/revisions"}],"predecessor-version":[{"id":1052041,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1052026\/revisions\/1052041"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1052039"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1052026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1052026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1052026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}