將 Pandas DataFrame 儲存為 PNG 映像
將 Pandas DataFrame 儲存為映像對於以視覺化可存取的格式呈現資料非常有用。雖然 HTML 轉換可以提供解決方案,但本文重點介紹建立 PNG 映像。
解
透過利用 matplotlib,Pandas 允許進行表格繪製。將表格儲存為PNG 影像而不產生不必要的美觀,請按照以下步驟操作:
<code class="python">import matplotlib.pyplot as plt import pandas as pd from pandas.plotting import table # Suppress axes and labels ax = plt.subplot(111, frame_on=False) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) table(ax, df) # Replace 'df' with your DataFrame # Save the plot as a PNG plt.savefig('mytable.png')</code>
多重索引模擬
應用上述方法時模擬多索引:
-
將多索引重置為正常columns:
<code class="python">df = df.reset_index()</code>
-
刪除重複的高階多索引列:
<code class="python">df.ix[df.duplicated('first') , 'first'] = ''</code>
-
將多索引列名稱替換為空strings:
<code class="python">new_cols = df.columns.values new_cols[:2] = '','' df.columns = new_cols</code>
-
將表格行標籤設定為空字串(以抑制顯示):
<code class="python">table(ax, df, rowLabels=['']*df.shape[0], loc='center')</code>
透過這些調整,多重索引表可以表示為PNG 影像。
棄用警告
- 表的 pandas.tools.plotting 導入已棄用。請改用 pandas.plotting。
- ix 索引器已棄用。請改用 loc。
以上是如何將 Pandas DataFrame 儲存為 PNG 映像?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Python是解釋型語言,但也包含編譯過程。 1)Python代碼先編譯成字節碼。 2)字節碼由Python虛擬機解釋執行。 3)這種混合機制使Python既靈活又高效,但執行速度不如完全編譯型語言。

UseeAforloopWheniteratingOveraseQuenceOrforAspecificnumberoftimes; useAwhiLeLoopWhenconTinuingUntilAcIntiment.forloopsareIdealForkNownsences,而WhileLeleLeleLeleLeleLoopSituationSituationsItuationsItuationSuationSituationswithUndEtermentersitations。

pythonloopscanleadtoerrorslikeinfiniteloops,modifyingListsDuringteritation,逐個偏置,零indexingissues,andnestedloopineflinefficiencies

forloopsareadvantageousforknowniterations and sequests,供應模擬性和可讀性;而LileLoopSareIdealFordyNamicConcitionSandunknowniterations,提供ControloperRoverTermination.1)forloopsareperfectForeTectForeTerToratingOrtratingRiteratingOrtratingRitterlistlistslists,callings conspass,calplace,cal,ofstrings ofstrings,orstrings,orstrings,orstrings ofcces

pythonisehybridmodeLofCompilation和interpretation:1)thepythoninterpretercompilesourcecececodeintoplatform- interpententbybytecode.2)thepythonvirtualmachine(pvm)thenexecutecutestestestestestesthisbytecode,ballancingEaseofuseEfuseWithPerformance。

pythonisbothinterpretedAndCompiled.1)它的compiledTobyTecodeForportabilityAcrosplatforms.2)bytecodeisthenInterpreted,允許fordingfordforderynamictynamictymictymictymictyandrapiddefupment,儘管Ititmaybeslowerthananeflowerthanancompiledcompiledlanguages。

在您的知識之際,而foroopsareideal insinAdvance中,而WhileLoopSareBetterForsituations則youneedtoloopuntilaconditionismet

ForboopSareSusedwhenthentheneMberofiterationsiskNownInAdvance,而WhileLoopSareSareDestrationsDepportonAcondition.1)ForloopSareIdealForiteratingOverSequencesLikelistSorarrays.2)whileLeleLooleSuitableApeableableableableableableforscenarioscenarioswhereTheLeTheLeTheLeTeLoopContinusunuesuntilaspecificiccificcificCondond


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具