Pandas Transforms
API Classes
The API Classes will often provide helpful methods that give you a DataFrame (data_source.query() for instance), so always check out the API Classes first.
These Transforms will give you the ultimate in customization and flexibility when creating AWS Machine Learning Pipelines. Grab a Pandas DataFrame from a DataSource or FeatureSet process in whatever way for your use case and simply create another Sageworks DataSource or FeatureSet from the resulting DataFrame.
Lots of Options:
Not for Large Data
Pandas Transforms can't handle large datasets (> 4 GigaBytes). For doing transforma on large data see our Heavy Transforms
- S3 --> DF --> DataSource
- DataSource --> DF --> DataSource
- DataSoruce --> DF --> FeatureSet
- Get Creative!
Welcome to the SageWorks Pandas Transform Classes
These classes provide low-level APIs for using Pandas DataFrames
- DataToPandas: Pull a dataframe from a SageWorks DataSource
- FeaturesToPandas: Pull a dataframe from a SageWorks FeatureSet
- PandasToData: Create a SageWorks DataSource using a Pandas DataFrame as the source
- PandasToFeatures: Create a SageWorks FeatureSet using a Pandas DataFrame as the source
- PandasToFeaturesChunked: Create a SageWorks FeatureSet using a Chunked/Streaming Pandas DataFrame as the source
DataToPandas
Bases: Transform
DataToPandas: Class to transform a Data Source into a Pandas DataFrame
Common Usage
Source code in src/sageworks/core/transforms/pandas_transforms/data_to_pandas.py
__init__(input_uuid)
DataToPandas Initialization
Source code in src/sageworks/core/transforms/pandas_transforms/data_to_pandas.py
get_output()
post_transform(**kwargs)
Post-Transform: Any checks on the Pandas DataFrame that need to be done
Source code in src/sageworks/core/transforms/pandas_transforms/data_to_pandas.py
transform_impl(query=None, max_rows=100000)
Convert the DataSource into a Pandas DataFrame Args: query(str): The query to run against the DataSource (default: None) max_rows(int): The maximum number of rows to return (default: 100000)
Source code in src/sageworks/core/transforms/pandas_transforms/data_to_pandas.py
FeaturesToPandas
Bases: Transform
FeaturesToPandas: Class to transform a FeatureSet into a Pandas DataFrame
Common Usage
Source code in src/sageworks/core/transforms/pandas_transforms/features_to_pandas.py
__init__(feature_set_name)
FeaturesToPandas Initialization
Source code in src/sageworks/core/transforms/pandas_transforms/features_to_pandas.py
get_output()
post_transform(**kwargs)
Post-Transform: Any checks on the Pandas DataFrame that need to be done
Source code in src/sageworks/core/transforms/pandas_transforms/features_to_pandas.py
transform_impl(max_rows=100000)
Convert the FeatureSet into a Pandas DataFrame
Source code in src/sageworks/core/transforms/pandas_transforms/features_to_pandas.py
PandasToData
Bases: Transform
PandasToData: Class to publish a Pandas DataFrame as a DataSource
Common Usage
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_data.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 98 99 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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
__init__(output_uuid, output_format='parquet')
PandasToData Initialization Args: output_uuid (str): The UUID of the DataSource to create output_format (str): The file format to store the S3 object data in (default: "parquet")
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_data.py
convert_datetime_columns(df)
staticmethod
Convert datetime columns to ISO-8601 string
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_data.py
convert_object_to_datetime(df)
Try to automatically convert object columns to datetime or string columns
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_data.py
convert_object_to_string(df)
Try to automatically convert object columns to string columns
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_data.py
post_transform(**kwargs)
Post-Transform: Calling onboard() fnr the DataSource
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_data.py
pre_transform(**kwargs)
set_input(input_df)
transform_impl(overwrite=True, **kwargs)
Convert the Pandas DataFrame into Parquet Format in the SageWorks S3 Bucket, and store the information about the data to the AWS Data Catalog sageworks database
Parameters:
Name | Type | Description | Default |
---|---|---|---|
overwrite
|
bool
|
Overwrite the existing data in the SageWorks S3 Bucket |
True
|
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_data.py
93 94 95 96 97 98 99 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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
PandasToFeatures
Bases: Transform
PandasToFeatures: Class to publish a Pandas DataFrame into a FeatureSet
Common Usage
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 98 99 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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
__init__(output_uuid)
PandasToFeatures Initialization
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_uuid
|
str
|
The UUID of the FeatureSet to create |
required |
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features.py
convert_column_types(df)
staticmethod
Convert the types of the DataFrame to the correct types for the Feature Store
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features.py
convert_columns_to_categorical(columns)
Convert column to Categorical type
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features.py
create_feature_group()
Create a Feature Group, load our Feature Definitions, and wait for it to be ready
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features.py
manual_categorical_converter()
Used for Streaming: Convert object and string types to Categorical
Note
This method is used for streaming/chunking. You can set the categorical_dtypes attribute to a dictionary of column names and their respective categorical types.
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features.py
one_hot_encode(df, one_hot_columns)
One Hot Encoding for Categorical Columns with additional column name management
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The DataFrame to process |
required |
one_hot_columns
|
list
|
The list of columns to one-hot encode |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The DataFrame with one-hot encoded columns |
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features.py
post_transform(**kwargs)
Post-Transform: Populating Offline Storage and onboard()
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features.py
pre_transform(**kwargs)
Pre-Transform: Delete any existing FeatureSet and Create the Feature Group
prep_dataframe()
Prep the DataFrame for Feature Store Creation
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features.py
process_column_name(column, shorten=False)
Call various methods to make sure the column is ready for Feature Store Args: column (str): The column name to process shorten (bool): Should we shorten the column name? (default: False)
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features.py
set_input(input_df, id_column, event_time_column=None, one_hot_columns=None)
Set the Input DataFrame for this Transform
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_df
|
DataFrame
|
The input DataFrame. |
required |
id_column
|
str
|
The ID column (must be specified, use "auto" for auto-generated IDs). |
required |
event_time_column
|
str
|
The name of the event time column (default: None). |
None
|
one_hot_columns
|
list
|
The list of columns to one-hot encode (default: None). |
None
|
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features.py
transform_impl()
Transform Implementation: Ingest the data into the Feature Group
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features.py
wait_for_rows(expected_rows)
Wait for AWS Feature Group to fully populate the Offline Storage
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features.py
PandasToFeaturesChunked
Bases: Transform
PandasToFeaturesChunked: Class to manage a bunch of chunked Pandas DataFrames into a FeatureSet
Common Usage
to_features = PandasToFeaturesChunked(output_uuid, id_column="id"/None, event_time_column="date"/None)
to_features.set_output_tags(["abalone", "public", "whatever"])
cat_column_info = {"sex": ["M", "F", "I"]}
to_features.set_categorical_info(cat_column_info)
to_features.add_chunk(df)
to_features.add_chunk(df)
...
to_features.finalize()
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features_chunked.py
__init__(output_uuid, id_column=None, event_time_column=None)
PandasToFeaturesChunked Initialization
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features_chunked.py
add_chunk(chunk_df)
Add a Chunk of Data to the FeatureSet
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features_chunked.py
post_transform(**kwargs)
pre_transform(**kwargs)
Pre-Transform: Create the Feature Group with Chunked Data
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features_chunked.py
set_categorical_info(cat_column_info)
Set the Categorical Columns Args: cat_column_info (dict[list[str]]): Dictionary of categorical columns and their possible values
Source code in src/sageworks/core/transforms/pandas_transforms/pandas_to_features_chunked.py
transform_impl()
Required implementation of the Transform interface