Python
 Computer >> コンピューター >  >> プログラミング >> Python

PythonPandas-インデックスの転置を返します


インデックスの転置を返すには、 index.Tを使用します プロパティ。

まず、必要なライブラリをインポートします-

import pandas as pd

インデックスの作成-

index = pd.Index(['Car','Bike','Truck','Ship','Airplane'])

インデックスを表示-

print("Pandas Index...\n",index)

インデックスの転置を表示-

print("\nTranspose of the Pandas Index which is by definition self...\n",index.T)

以下はコードです-

import pandas as pd

# Creating the index
index = pd.Index(['Car','Bike','Truck','Ship','Airplane'])

# Display the index
print("Pandas Index...\n",index)

# Return an array representing the data in the Index
print("\nArray...\n",index.values)

# Display the transpose of the index
print("\nTranspose of the Pandas Index which is by definition self...\n",index.T)

出力

これにより、次のコードが生成されます-

Pandas Index...
Index(['Car', 'Bike', 'Truck', 'Ship', 'Airplane'], dtype='object')

Array...
['Car' 'Bike' 'Truck' 'Ship' 'Airplane']

Transpose of the Pandas Index which is by definition self...
Index(['Car', 'Bike', 'Truck', 'Ship', 'Airplane'], dtype='object')

  1. Python-Pandasインデックスの最小値を返します

    パンダインデックスの最小値を返すには、 index.min()を使用します 方法。まず、必要なライブラリをインポートします- import pandas as pd パンダインデックスの作成- index = pd.Index([10.5, 20.4, 40.5, 25.6, 5.7, 6.8, 30.8, 50.2]) パンダのインデックスを表示する- print("Pandas Index...\n",index) 最小値を取得- print("\nMinimum value..\n", index.min()) 例 以下はコードです-

  2. PythonPandas-IntervalArray内の各間隔の中点をインデックスとして返します

    IntervalArray内の各間隔の中点をインデックスとして返すには、 array.midを使用します 財産。最初は まず、必要なライブラリをインポートします- import pandas as pd 2つのIntervalオブジェクトを作成します。値が「both」の「closed」パラメータを使用して設定された閉じた間隔- interval1 = pd.Interval(50, 75, closed='both') interval2 = pd.Interval(65, 90, closed='both') 間隔を表示する- print("I