{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pwd" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data_dir = \"/home/ec2-user/SageMaker/aws-recomendador-anime/recomendador-de-anime/anime-data\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "anime_with_synopsis = pd.read_csv(data_dir + '/anime_with_synopsis.csv',index_col='MAL_ID')\n", "anime_with_synopsis.sample(5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Crear columna Name_Lower" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "anime_with_synopsis['Name_Lower'] = anime_with_synopsis['Name'].str.lower()\n", "anime_with_synopsis.sample(5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "new_anime_with_synopsis = \"new_anime_with_synopsis.csv\"\n", "anime_with_synopsis.to_csv((data_dir+\"/\"+new_anime_with_synopsis), index=True, float_format='%.0f')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "## Copiar archivo en S3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Copiar archivo en S3" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import boto3\n", "import json" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "with open('/opt/ml/metadata/resource-metadata.json') as notebook_info:\n", " data = json.load(notebook_info)\n", " resource_arn = data['ResourceArn']\n", " region = resource_arn.split(':')[3]\n", "print(region)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s3 = boto3.client('s3')\n", "account_id = boto3.client('sts').get_caller_identity().get('Account')\n", "bucket_name = account_id + \"-\" + region + \"-\" + \"personalize-anime-dataset1\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data_file_path = f\"{data_dir}/{new_anime_with_synopsis}\"\n", "boto3.Session().resource('s3').Bucket(bucket_name).Object(new_anime_with_synopsis).upload_file(data_file_path)\n", "s3DataPath = \"s3://\"+bucket_name+\"/\"+data_file_path" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.6 64-bit", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.6" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" } } }, "nbformat": 4, "nbformat_minor": 2 }