PythonPandas-期間の2番目のコンポーネントを取得します
期間の2番目のコンポーネントを取得するには、 period.secondを使用します 財産。まず、必要なライブラリをインポートします-
import pandas as pd
pandas.Periodは期間を表します。 2つのPeriodオブジェクトの作成
period1 = pd.Period("2020-09-23 05:55:30")
period2 = pd.Period(freq="S", year = 2021, month = 7, day = 16, hour = 2, minute = 35, second = 10) 期間オブジェクトを表示する
print("Period1...\n", period1)
print("Period2...\n", period2) 2つのPeriodオブジェクトから秒を取得します
res1 = period1.second res2 = period2.second
例
以下はコードです
import pandas as pd
# The pandas.Period represents a period of time
# creating two Period objects
period1 = pd.Period("2020-09-23 05:55:30")
period2 = pd.Period(freq="S", year = 2021, month = 7, day = 16, hour = 2, minute = 35, second = 10)
# display the Period objects
print("Period1...\n", period1)
print("Period2...\n", period2)
# get the seconds from two Period objects
res1 = period1.second
res2 = period2.second
# Return the seconds from the two Period objects
print("\nSeconds component from the 1st Period object ...\n", res1)
print("\nSeconds component from the 1st Period object ...\n", res2) 出力
これにより、次のコードが生成されます
Period1... 2020-09-23 05:55:30 Period2... 2021-07-16 02:35:10 Seconds component from the 1st Period object ... 30 Seconds component from the 1st Period object ... 10
-
PythonPandas-期間が含まれる曜日を取得します
期間が該当する曜日を取得するには、 period.dayofweekを使用します プロパティ まず、必要なライブラリをインポートします- import pandas as pd pandas.Periodは期間を表します。 2つのPeriodオブジェクトの作成- period1 = pd.Period("2021-09-18") period2 = pd.Period(freq ='D', year = 2021, month = 9, day = 22, hour = 4, minute = 55) 期間オブジェクトを表示する- print(&quo
-
PythonPandas-生理が始まる月の日を取得します
期間が該当する月の日を取得するには、 period.dayを使用します プロパティ。 まず、必要なライブラリをインポートします- import pandas as pd pandas.Periodは期間を表します。 2つのPeriodオブジェクトの作成- period1 = pd.Period("2021-09-18") period2 = pd.Period(freq ='D', year = 2021, month = 9, day = 22, hour = 4, minute = 55) 2つのPeriodオブジェクトから月の日を取得します- r