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

PythonPandas-オフセットオブジェクトに適用される頻度の名前を返します


オフセットオブジェクトに適用される頻度の名前を返すには、Pandasのoffset.nameプロパティを使用します。まず、必要なライブラリをインポートします-

from pandas.tseries.frequencies import to_offset
import pandas as pd

パンダでタイムスタンプオブジェクトを設定します-

timestamp = pd.Timestamp('2021-09-26 03:25:02.000045')

DateOffsetを作成します。ここでは、「M」頻度を使用して月をインクリメントしています-

offset = to_offset("3M")

更新されたタイムスタンプを表示する-

print("\nUpdated Timestamp...\n",timestamp + offset)

指定されたDateOffsetオブジェクトに適用された頻度の名前を返します-

print("\nThe name of the frequency on the DateOffset object..\n",
offset.name)

以下はコードです-

from pandas.tseries.frequencies import to_offset
import pandas as pd

# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-09-26 03:25:02.000045')

# Display the Timestamp
print("Timestamp...\n",timestamp)

# Create the DateOffset
# We are incrementing the months here using the "M" frequency
offset = to_offset("3M")

# Display the DateOffset
print("\nDateOffset...\n",offset)

# Display the Updated Timestamp
print("\nUpdated Timestamp...\n",timestamp + offset)

# return the name of the frequency applied on the given DateOffset object
print("\nThe name of the frequency on the DateOffset object..\n", offset.name)

出力

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

Timestamp...
 2021-09-26 03:25:02.000045

DateOffset...
 <3 * MonthEnds>

Updated Timestamp...
 2021-11-30 03:25:02.000045

The name of the frequency on the DateOffset object..
 M

  1. PythonPandas-Periodオブジェクトを分単位の頻度のタイムスタンプとして返​​します

    Periodオブジェクトを月次頻度のタイムスタンプとして返​​すには、 period.to_timestamp()を使用します メソッドを実行し、freqパラメータを「 T」として設定します ’。 まず、必要なライブラリをインポートします- import pandas as pd pandas.Periodは期間を表します。期間オブジェクトの作成 period = pd.Period(freq="S", year = 2021, month = 11, day = 26, hour = 11, minute = 45, second = 55) 期間オブジェクトを表

  2. PythonPandas-Periodオブジェクトを月次頻度のタイムスタンプとして返​​します

    Periodオブジェクトを月次頻度のタイムスタンプとして返​​すには、 period.to_timestamp()を使用します メソッドを実行し、freqパラメータを「 M」として設定します ’。 まず、必要なライブラリをインポートします- import pandas as pd pandas.Periodは期間を表します。期間オブジェクトの作成 period = pd.Period(freq="S", year = 2021, month = 9, day = 18, hour = 17, minute = 20, second = 45) 期間オブジェクトを表示