Types
Data exporter
Once you’re done transforming your data, write code in these types of blocks to store that data or to train models and store those models elsewhere.
Example
from mage_ai.io.file import FileIO
from pandas import DataFrame
@data_exporter
def export_data_to_file(df: DataFrame, **kwargs):
filepath = 'path/to/write/dataframe/to.csv'
FileIO().export(df, filepath)
Sample code:
from mage_ai.settings.repo import get_repo_path
from mage_ai.io.config import ConfigFileLoader
from mage_ai.io.s3 import S3
from pandas import DataFrame
from os import path
if 'data_exporter' not in globals():
from mage_ai.data_preparation.decorators import data_exporter
@data_exporter
def export_data_to_s3(df: DataFrame, **kwargs) -> None:
"""
Template for exporting data to a S3 bucket.
Specify your configuration settings in 'io_config.yaml'.
Docs: https://github.com/mage-ai/mage-ai/blob/master/docs/blocks/data_loading.md#s3
"""
config_path = path.join(get_repo_path(), 'io_config.yaml')
config_profile = 'default'
bucket_name = 'samurai-operator'
object_key = 'user_profiles_transformed.csv'
return S3.with_config(ConfigFileLoader(config_path, config_profile)).export(
df,
bucket_name,
object_key,
)