Learn how to create a robust date table by leveraging a simple Python script that will allow you to create a host of different time segments for an awesome customized calendar table.
You can copy and paste the code:
import pandas as pd
start= '1/1/2020'
end = '12/31/2020'
df= pd.DataFrame(pd.date_range(start,end,freq="H",tz='EST'),columns =['Datetime'])
df['LocaleTime'] = df["Datetime"].dt.strftime('%c')
df['Day'] =df["Datetime"].dt.day
df['Month'] = df["Datetime"].dt.month
df['Year'] = df["Datetime"].dt.year
df['time'] =df["Datetime"].dt.time
df['timezone'] =df["Datetime"].dt.tz
df['Hour'] =df["Datetime"].dt.hour
df['Quarter'] =df["Datetime"].dt.quarter
df['MonthName'] = df["Datetime"].dt.strftime('%b')
df['Week Name'] = df["Datetime"].dt.strftime('%A')
df['WeekNumber'] = df["Datetime"].dt.strftime('%W')
df['Weekday'] = df["Datetime"].dt.weekday
df['TimeofDay'] = df["Datetime"].dt.strftime('%p')
df['UTC_offset'] = df["Datetime"].dt.strftime('%z')
df['DayofYEar'] = df["Datetime"].dt.dayofyear
df['Century'] = df["Datetime"].dt.strftime('%Y')
You can find the Jupyter Notebook here for the code here:
https://github.com/Gaelim/PowerBI_dat...
Please find the resources here for adding more customization with Pandas datetime:
https://pandas.pydata.org/docs/refere...
https://docs.python.org/3/library/dat...
#PowerBI
#Python
#DateTable
#CalendarTable
#TimeIntelligence
コメント