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

PythonPandas-Periodオブジェクトのタイムスタンプ表現を返します


Periodオブジェクトのタイムスタンプ表現を返すには、 period.to_timestamp()を使用します メソッド。

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

import pandas as pd

pandas.Periodは期間を表します。期間オブジェクトの作成

period = pd.Period(freq="S", year = 2021, month = 9, day = 18, hour = 17, minute = 20, second = 45)

期間オブジェクトを表示する

print("Period...\n", period)

Periodオブジェクトのタイムスタンプ表現を返します。 「freq」パラメータを使用して周波数を設定しました

print("\nPeriod to Timestamp...\n", period.to_timestamp(freq='T'))

以下はコードです

import pandas as pd

# The pandas.Period represents a period of time
# Creating a Period object
period = pd.Period(freq="S", year = 2021, month = 9, day = 18, hour = 17, minute = 20, second = 45)

# display the Period object
print("Period...\n", period)

# Return the Timestamp representation of the Period object
# We have set the frequency using the "freq" parameter
print("\nPeriod to Timestamp...\n", period.to_timestamp(freq='T'))

出力

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

Period...
2021-09-18 17:20:45

Period to Timestamp...
2021-09-18 17:20:00

  1. PythonPandas-Timedeltaオブジェクトからマイクロ秒を返します

    Timedeltaオブジェクトからマイクロ秒を返すには、 timedelta.microsecondsを使用します 財産。まず、必要なライブラリをインポートします- import pandas as pd TimeDeltasは、Pythonの標準の日時ライブラリであり、異なる表現のtimedeltaを使用します。 Timedeltaオブジェクトを作成する timedelta = pd.Timedelta('7 days 20 min 15 s 35 ms') マイクロ秒の値を返す timedelta.microseconds 例 以下はコードです import pa

  2. PythonPandas-Timedeltaオブジェクトの最大値を返します

    Timedeltaオブジェクトの最大値を返すには、 timedelta.max 財産。まず、必要なライブラリをインポートします- import pandas as pd Timedeltaオブジェクトを作成する timedelta = pd.Timedelta('5 days 1 min 45 s 40 ns') 最大値を返す timedelta.max 例 以下はコードです import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different r