This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(sparklyr) | |
| SparkR::sparkR.session() | |
| sc <- spark_connect(method="databricks") | |
| snow.df.sparklyr <- spark_read_source( | |
| sc=sc, | |
| name = "adult", | |
| source = "snowflake", | |
| options = list( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| def create_date_window(in_date, window_size): | |
| date_lower = pd.to_datetime(in_date) - pd.DateOffset(days=window_size) | |
| date_upper = pd.to_datetime(in_date) + pd.DateOffset(days=window_size) | |
| return date_lower, date_upper | |
| if __name__ == "__main__": | |
| print(create_date_window("2019-09-17", 28)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pyspark.sql.functions import array, col, explode, lit, struct | |
| from pyspark.sql import DataFrame | |
| from typing import Iterable | |
| def melt( | |
| df: DataFrame, | |
| id_vars: Iterable[str], value_vars: Iterable[str], | |
| var_name: str="variable", value_name: str="value") -> DataFrame: | |
| """Convert :class:`DataFrame` from wide to long format.""" |
NewerOlder