Pandas を使用した積み上げ棒グラフのプロット
Python では、Pandas と Matplotlib を使用して積み上げ棒グラフを作成できます。一般的な課題は、グラフのデータを構造化することです。
たとえば、データが複数の列に分割された積み上げ棒グラフを作成するタスクを考えてみましょう。指定された例は、サイト名と不正行為/NFF 数を含むスプレッドシートを示しています。このデータをプロットするには:
- ライブラリのインポート: Pandas と Matplotlib をインポートすることから始めます。
- データ フレームの作成: Pandas データフレームを作成します。
- データの再構築: groupby() 関数と unstack() 関数を使用して、棒グラフに適した形式にデータを再構築します。この例では、データはサイト名と不正行為/NFF によってグループ化され、その後、カウントが積み上げられません。
- 棒グラフの作成: kind=' を指定して、plot() 関数を使用します。 bar' および stacked=True 引数を使用して積み上げ棒グラフを作成します。
- Label Axes: x 軸と y 軸にラベルを付けることを忘れないでください。
コード例:
import pandas as pd import matplotlib.pyplot as plt # Create DataFrame from CSV data df = pd.read_csv('data.csv') # Restructure data df2 = df.groupby(['Site Name', 'Abuse/NFF'])['Site Name'].count().unstack('Abuse/NFF').fillna(0) # Create bar chart df2[['abuse', 'nff']].plot(kind='bar', stacked=True) plt.xlabel('Site Name') plt.ylabel('Count') plt.title('Stacked Bar Chart of Abuse and NFF') plt.show()
以上がデータが複数の列に分割されている場合にパンダで積み上げ棒グラフをプロットするにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

pythonusesahybridmodelofcompilation andtertation:1)thepythoninterpretercompilessourcodeodeplatform-indopent bytecode.2)thepythonvirtualmachine(pvm)thenexecuteTesthisbytecode、balancingeaseoputhswithporformance。

pythonisbothintersedand compiled.1)it'scompiledtobytecode forportabalityacrossplatforms.2)bytecodeisthenは解釈され、開発を許可します。

loopsareideal whenyouwhenyouknumberofiterationsinadvance、foreleloopsarebetterforsituationsは、loopsaremoreedilaConditionismetを使用します

henthenumber ofiterationsisknown advanceの場合、dopendonacondition.1)forloopsareideal foriterating over for -for -for -saredaverseversives likelistorarrays.2)whileopsaresupasiable forsaresutable forscenarioswheretheloopcontinupcontinuspificcond

pythonisnotpurelyLepted; itusesahybridapproachofbytecodecodecodecodecodecodedruntimerttation.1)pythoncompilessourcodeintobytecode、whodythepythonvirtualmachine(pvm).2)

ToconcatenateListsinpythothesheElements、使用:1)Operatortokeepduplicates、2)asettoremoveduplicates、or3)listcomplunting for controloverduplicates、各メトドハスディフェルフェルフェントパフォーマンスアンドソーダーインプリテーション。

pythonisantertedlanguage、useaseofuseandflexibility-butfactingporformantationationsincriticalapplications.1)解釈されたlikepythonexecuteline-by-lineを解釈します

Useforloopswhenthenumberofiterationsisknowninadvance、andwhiloopswheniterationsdependonacondition.1)forloopsareidealforsecenceslikelistoranges.2)


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

Dreamweaver Mac版
ビジュアル Web 開発ツール

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

SublimeText3 中国語版
中国語版、とても使いやすい

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!
