Power BI : Basic Forecast Method Using Date Tables (R and Python)
Dave's Data Analytics
#powerbi, #forecast, #rprogramming A quick video demo on how to create a date table with R. And use Merge table function in Power BI and finaly doing a price forecast using 2020 data.
===== R Date Table =======
Load the 'lubridate' package for date operations
library(lubridate)
Create a vector of dates from January 1st, 2020 to January 31st, 2021
start_date = as.Date("2010-01-19") end_date = as.Date("2020-09-25") date_table = seq(start_date, end_date, by = "day")
Convert the date_table to a data frame and set the column name
date_table = as.data.frame(date_table) colnames(date_table) = "Date"
Print the date_table
tail(date_table)
Write data to csv file
write.csv(date_table,file='./NIKE-Calendar.csv',row.names = F)
===== Python Date Table ======= import pandas as pd from datetime import date, timedelta
Create a range of dates from January 1st, 2010 to September 25th, 2020
start_date = date(2010, 1, 19) end_date = date(2020, 9, 25) date_range = pd.date_range(start=start_date, end=end_date, freq='D')
Convert the date_range to a DataFrame and set the column name
date_table = pd.DataFrame(date_range, columns=['Date'])
Print the last few rows of date_table
print(date_table.tail())
Write data to a CSV file
date_table.to_csv('./NIKE-Calendar.csv', index=False)
167206476 Bytes