{ "cells": [ { "cell_type": "markdown", "id": "bd938e6e", "metadata": {}, "source": [ "**Short notebook to test connectivity with S3 services and explore the data**" ] }, { "cell_type": "code", "execution_count": 1, "id": "127753ac", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "id": "ae3c64fe", "metadata": {}, "outputs": [], "source": [ "import os\n", "import s3fs\n", "fs = s3fs.S3FileSystem(\n", " client_kwargs={'endpoint_url': 'https://'+'minio-simple.lab.groupe-genes.fr'},\n", " key = os.environ[\"AWS_ACCESS_KEY_ID\"], \n", " secret = os.environ[\"AWS_SECRET_ACCESS_KEY\"], \n", " token = os.environ[\"AWS_SESSION_TOKEN\"])" ] }, { "cell_type": "code", "execution_count": 3, "id": "84b9ac42", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "def sample_by_blocks(df, block_size=10, num_blocks=10, random_state=None):\n", " \"\"\"Sample num_blocks blocks of block_size consecutive rows (no overlapping blocks).\"\"\"\n", " n = len(df)\n", " max_start = n - block_size\n", " if max_start < 0:\n", " raise ValueError(f\"DataFrame has {n} rows, need at least {block_size}\")\n", " if max_start + 1 < num_blocks:\n", " raise ValueError(f\"Not enough room for {num_blocks} non-overlapping blocks (need at least {num_blocks * block_size} rows)\")\n", " rng = np.random.default_rng(random_state)\n", " chosen_starts = rng.choice(max_start + 1, size=num_blocks, replace=False)\n", " chosen_starts.sort() # blocks in order of position in original df\n", " indices = np.concatenate([np.arange(s, s + block_size) for s in chosen_starts])\n", " return df.iloc[indices].reset_index(drop=True)\n", "\n", "# sample_df = sample_by_blocks(df, block_size=10, num_blocks=10, random_state=42)" ] }, { "cell_type": "code", "execution_count": 9, "id": "83472648", "metadata": {}, "outputs": [], "source": [ "with fs.open('s3://projet-bdc-data/carmignac/Data Modélisation/market data/esterRates.csv', 'rb') as f:\n", " df = pd.read_csv(f, sep =\";\")\n", "\n", "sample_df = df" ] }, { "cell_type": "code", "execution_count": 10, "id": "79af063e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | Date | \n", "Yld to Maturity | \n", "
|---|---|---|
| 0 | \n", "31/12/2014 | \n", "0.144 | \n", "
| 1 | \n", "02/01/2015 | \n", "-0.079 | \n", "
| 2 | \n", "05/01/2015 | \n", "-0.074 | \n", "
| 3 | \n", "06/01/2015 | \n", "-0.075 | \n", "
| 4 | \n", "07/01/2015 | \n", "-0.069 | \n", "
| ... | \n", "... | \n", "... | \n", "
| 2821 | \n", "16/10/2025 | \n", "1.928 | \n", "
| 2822 | \n", "17/10/2025 | \n", "1.928 | \n", "
| 2823 | \n", "20/10/2025 | \n", "1.928 | \n", "
| 2824 | \n", "21/10/2025 | \n", "1.927 | \n", "
| 2825 | \n", "22/10/2025 | \n", "1.928 | \n", "
2826 rows × 2 columns
\n", "