Pandas တွင် အချိန်တံဆိပ်ကို ရက်စွဲ/အချိန်သို့ မည်သို့ပြောင်းလဲမည်နည်း။
ပန်ဒါ DataFrame တွင် အချိန်တံဆိပ်တစ်ခုအား datetime သို့ပြောင်းလဲရန် အောက်ပါအခြေခံ syntax ကို သင်အသုံးပြုနိုင်သည်-
timestamp. to_pydatetime ()
အောက်ဖော်ပြပါ ဥပမာများသည် ဤလုပ်ဆောင်ချက်ကို လက်တွေ့အသုံးချနည်းကို ပြသထားသည်။
ဥပမာ 1- အချိန်တံဆိပ်တစ်ခုတည်းကို ရက်စွဲ/အချိန်အဖြစ် ပြောင်းပါ။
အောက်ပါကုဒ်သည် အချိန်တံဆိပ်တစ်ခုအား ရက်စွဲအချိန်တစ်ခုသို့ မည်သို့ပြောင်းလဲရမည်ကို ပြသသည်-
#define timestamp stamp = pd. Timestamp (' 2021-01-01 00:00:00 ') #convert timestamp to datetime stamp. to_pydatetime () datetime.datetime(2021, 1, 1, 0, 0)
ဥပမာ 2- Timestamps ၏ Array တစ်ခုအား Datetimes သို့ပြောင်းပါ။
အောက်ဖော်ပြပါ ကုဒ်သည် အချိန်တံဆိပ်တုံးများ၏ အခင်းအကျင်းတစ်ခုအား ရက်စွဲအချိန်သို့ မည်သို့ပြောင်းလဲရမည်ကို ပြသသည်-
#define array of timestamps stamps = pd. date_range (start=' 2020-01-01 12:00:00 ', periods= 6 , freq=' H ') #view array of timestamps stamps DatetimeIndex(['2020-01-01 12:00:00', '2020-01-01 13:00:00', '2020-01-01 14:00:00', '2020-01-01 15:00:00', '2020-01-01 16:00:00', '2020-01-01 17:00:00'], dtype='datetime64[ns]', freq='H') #convert timestamps to datetimes stamps. to_pydatetime () array([datetime.datetime(2020, 1, 1, 12, 0), datetime.datetime(2020, 1, 1, 13, 0), datetime.datetime(2020, 1, 1, 14, 0), datetime.datetime(2020, 1, 1, 15, 0), datetime.datetime(2020, 1, 1, 16, 0), datetime.datetime(2020, 1, 1, 17, 0)], dtype=object)
ဥပမာ 3- Timestamps ၏ Pandas ကော်လံကို Datetimes သို့ပြောင်းပါ။
အောက်ပါကုဒ်သည် အချိန်တံဆိပ်တုံးများ၏ ပန်ဒါကော်လံတစ်ခုကို ရက်စွဲအချိန်သို့ မည်သို့ပြောင်းလဲရမည်ကို ပြသသည်-
import pandas as pd
#createDataFrame
df = pd. DataFrame ({' stamps ': pd. date_range (start=' 2020-01-01 12:00:00 ',
periods= 6 ,
freq=' H '),
' sales ': [11, 14, 25, 31, 34, 35]})
#convert column of timestamps to datetimes
df. stamps = df. stamps . apply (lambda x: x.date ())
#view DataFrame
df
dirty stamps
0 2020-01-01 11
1 2020-01-01 14
2 2020-01-01 25
3 2020-01-01 31
4 2020-01-01 34
5 2020-01-01 35
ထပ်လောင်းအရင်းအမြစ်များ
Pandas တွင် DateTime ကို ရက်စွဲသို့ မည်သို့ပြောင်းလဲမည်နည်း။
Pandas ရှိ ကော်လံများကို DateTime သို့ ပြောင်းလဲနည်း
ရက်စွဲအလိုက် Pandas DataFrame ကို ဘယ်လိုစီမလဲ။