複数の条件で NumPy "where" を使用する
データ操作タスクを使用する場合、多くの場合、選択または変更するために異なる条件を適用する必要があります。特定の値。 NumPy の「where」関数は、条件付き操作のための強力なツールですが、デフォルトでは 2 つの条件のみを処理します。
というパンダ データフレームに新しい列「energy_class」を追加する場合を考えてみましょう。 「df_energy」。エネルギー クラスは、次の条件に基づいて割り当てる必要があります。
- 「consumption_energy」値が 400 を超える場合: 「高」
- 「consumption_energy」値が 200 ~ 400 の場合: 「中」
- "consumption_energy" 値が 200 以下: "low"
NumPy の "where" 関数は複数の条件をサポートしていないため、解決策はより強力な関数を使用することにあります。兄弟、「選択してください。」この問題に対処する方法は次のとおりです。
import numpy as np # Assuming df_energy has a column called "consumption_energy" col = 'consumption_energy' conditions = [ df_energy[col] >= 400, (df_energy[col] 200), df_energy[col] <p>この「select」の拡張使用法により、複数の条件を定義し、対応する選択肢を出力にマップすることができます。デフォルトでは、どの条件も満たされない場合、「np.nan」が割り当てられます。</p><p>その結果、DataFrame の「energy_class」列には、指定した条件に基づいて適切なラベルが設定されます。エネルギー消費レベルの明確な分類</p>
以上が条件付き操作のために複数の条件を指定して NumPy「where」を使用する方法は?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

Pythonlistscanstoreanydatatype,arraymodulearraysstoreonetype,andNumPyarraysarefornumericalcomputations.1)Listsareversatilebutlessmemory-efficient.2)Arraymodulearraysarememory-efficientforhomogeneousdata.3)NumPyarraysareoptimizedforperformanceinscient

heouttemptemptostoreavure ofthewrongdatatypeinapythonarray、yure counteractypeerror.thisduetothearraymodule'sstricttypeeencultionyを使用します

PythonListSarePartOfThestAndardarenot.liestareBuilting-in、versatile、forStoringCollectionsのpythonlistarepart。

theScriptisrunningwithwrongthonversionduetorectRectDefaultEntertersettings.tofixthis:1)CheckthedededefaultHaulthonsionsingpython - versionorpython3-- version.2)usevirtualenvironmentsbycreatingonewiththon3.9-mvenvmyenv、andverixe

PythonArraysSupportVariousoperations:1)SlicingExtractsSubsets、2)Appending/ExtendingAdddesements、3)inSertingSelementSatspecificpositions、4)remvingingDeletesements、5)sorting/verversingsorder、and6)listenionsionsionsionsionscreatenewlistsebasedexistin

numpyarraysAressertialentionsionceivationsefirication-efficientnumericalcomputations andDatamanipulation.theyarecrucialindatascience、mashineelearning、物理学、エンジニアリング、および促進可能性への適用性、scaledatiencyを効率的に、forexample、infinancialanalyyy

UseanArray.ArrayOverAlistinPythonは、Performance-criticalCode.1)homogeneousdata:araysavememorywithpedelements.2)Performance-criticalcode:Araysofterbetterbetterfornumerumerumericaleperations.3)interf

いいえ、notallistoperationSaresuptedbyarrays、andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorintorintorinsertizizing、whosimpactsporformance.2)リスト


ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

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

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

WebStorm Mac版
便利なJavaScript開発ツール

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

ホットトピック









