DataFrame Utilities¶
create_date_dataframe ¶
create_date_dataframe(spark: SparkSession, start_date: Union[str, date, datetime], end_date: Union[str, date, datetime], *, date_col: str = 'date') -> DataFrame
Return contiguous dates between start_date and end_date inclusive with calendar attributes.
Source code in src/spark_fuse/utils/dataframe.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
create_time_dataframe ¶
create_time_dataframe(spark: SparkSession, start_time: Union[str, time, datetime], end_time: Union[str, time, datetime], *, interval_seconds: int = 60, time_col: str = 'time') -> DataFrame
Return evenly spaced times between start_time and end_time (inclusive) with clock units.
Source code in src/spark_fuse/utils/dataframe.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
ensure_columns ¶
ensure_columns(df: DataFrame, required: Iterable[str]) -> DataFrame
Validate that df contains all required columns.
Raises a ValueError including the missing columns otherwise.
Source code in src/spark_fuse/utils/dataframe.py
25 26 27 28 29 30 31 32 33 | |
preview ¶
preview(df: DataFrame, n: int = 5) -> str
Return a string preview of the dataframe head and schema.
Source code in src/spark_fuse/utils/dataframe.py
18 19 20 21 22 | |