{ "cells": [ { "cell_type": "markdown", "id": "46102be7-d318-480c-ad7a-be28ebc7b8d5", "metadata": {}, "source": [ "# Gold vers DataMart" ] }, { "cell_type": "code", "execution_count": 1, "id": "a7ebc69e-a43f-4118-b1e1-104c7794dd6d", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from pathlib import Path" ] }, { "cell_type": "code", "execution_count": 2, "id": "b148ae5c-0e77-47d1-a7df-bbdc3e8cf5a4", "metadata": {}, "outputs": [], "source": [ "gold_path = Path(\"../PLESNA Compta SYSTEM/gold\")\n", "assert gold_path.exists()\n", "mart_path = Path(\"../PLESNA Compta SYSTEM/datamart\")\n", "assert mart_path.exists()" ] }, { "cell_type": "code", "execution_count": 3, "id": "aa5d5183-b85c-4414-aa2a-50ccc15162ac", "metadata": {}, "outputs": [], "source": [ "def to_csv(df, dest):\n", " if dest.exists():\n", " df.to_csv(dest, mode=\"a\", header=False, index=False)\n", " else:\n", " df.to_csv(dest, index=False)" ] }, { "cell_type": "code", "execution_count": 4, "id": "82123895-95a4-4bd6-a794-9b891bd38c7b", "metadata": {}, "outputs": [], "source": [ "for f in mart_path.glob(\"**/*.csv\"):\n", " f.unlink()" ] }, { "cell_type": "markdown", "id": "9d0f4705-ae39-4517-b195-82b63f8660b4", "metadata": {}, "source": [ "## Agrégation de toute la CRG" ] }, { "cell_type": "code", "execution_count": 5, "id": "c009306d-92d8-42f1-8916-b1d275eae097", "metadata": {}, "outputs": [], "source": [ "crg_path = gold_path/\"CRG\"\n", "assert crg_path.exists()\n", "crg_files = list(crg_path.glob(\"*.csv\"))" ] }, { "cell_type": "code", "execution_count": 6, "id": "147c215e-4fb9-4108-9644-bdb5366108df", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "../PLESNA Compta SYSTEM/gold/CRG/2020.csv\n", "../PLESNA Compta SYSTEM/gold/CRG/2018.csv\n", "../PLESNA Compta SYSTEM/gold/CRG/2022.csv\n", "../PLESNA Compta SYSTEM/gold/CRG/2021.csv\n", "../PLESNA Compta SYSTEM/gold/CRG/2023.csv\n", "../PLESNA Compta SYSTEM/gold/CRG/2019.csv\n", "../PLESNA Compta SYSTEM/gold/CRG/2017.csv\n" ] } ], "source": [ "dfs = []\n", "for f in crg_files:\n", " print(f)\n", " dfs.append(pd.read_csv(f))\n", "df_crg = pd.concat(dfs)" ] }, { "cell_type": "markdown", "id": "ace5b951-8a2e-4a32-8d17-ce06ebdab3d4", "metadata": {}, "source": [ "## Agrégation de toute la banque" ] }, { "cell_type": "code", "execution_count": 7, "id": "e43ddf17-578c-46d9-9f8f-14decd2794f9", "metadata": {}, "outputs": [], "source": [ "banque_path = gold_path / \"Banque\"\n", "assert banque_path.exists()\n", "banque_files = list(banque_path.glob(\"*.csv\"))" ] }, { "cell_type": "code", "execution_count": 8, "id": "9dbc75a5-6d53-4fd3-81ab-1f3f37342603", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "../PLESNA Compta SYSTEM/gold/Banque/2020.csv\n", "../PLESNA Compta SYSTEM/gold/Banque/2022.csv\n", "../PLESNA Compta SYSTEM/gold/Banque/2021.csv\n" ] } ], "source": [ "dfs = []\n", "for f in banque_files:\n", " print(f)\n", " dfs.append(pd.read_csv(f))\n", "df_banque = pd.concat(dfs)" ] }, { "cell_type": "markdown", "id": "8cfae0d0-f437-456d-bbc7-cb4cb596f5e9", "metadata": {}, "source": [ "## Lots" ] }, { "cell_type": "code", "execution_count": 9, "id": "d8483ebe-70e2-4649-a772-2331f36e0af7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
RégieImmeublePorteLotAnnéeMoisCatégorieFournisseurLibelléDébitCréditImpact
0Imi GéranceB9B0920201Loyer ChargeNaNRègl. Loyer 01/20200.0100.48100.48
1Imi GéranceS5S0520201Loyer ChargeNaNRègl. Prov. Char 01/20200.0191.00191.00
2Imi GéranceS5S0520201Loyer ChargeNaNRègl. Loyer 01/20200.0745.39745.39
3Imi GéranceS2S0220201Loyer ChargeNaNRègl. Prov. Char 01/20200.0519.00519.00
4Imi GéranceS2S0220201Loyer ChargeNaNRègl. Loyer 01 à 03/20200.03473.793473.79
\n", "
" ], "text/plain": [ " Régie Immeuble Porte Lot Année Mois Catégorie Fournisseur \\\n", "0 Imi Gérance B 9 B09 2020 1 Loyer Charge NaN \n", "1 Imi Gérance S 5 S05 2020 1 Loyer Charge NaN \n", "2 Imi Gérance S 5 S05 2020 1 Loyer Charge NaN \n", "3 Imi Gérance S 2 S02 2020 1 Loyer Charge NaN \n", "4 Imi Gérance S 2 S02 2020 1 Loyer Charge NaN \n", "\n", " Libellé Débit Crédit Impact \n", "0 Règl. Loyer 01/2020 0.0 100.48 100.48 \n", "1 Règl. Prov. Char 01/2020 0.0 191.00 191.00 \n", "2 Règl. Loyer 01/2020 0.0 745.39 745.39 \n", "3 Règl. Prov. Char 01/2020 0.0 519.00 519.00 \n", "4 Règl. Loyer 01 à 03/2020 0.0 3473.79 3473.79 " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_crg.head()" ] }, { "cell_type": "code", "execution_count": 10, "id": "4fcc7d32-1923-4fcb-a411-6d72ac33843b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "../PLESNA Compta SYSTEM/datamart/Lot/B09.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S05.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S02.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S10.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/M05.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B07.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B14.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B10.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B02.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/M04.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S04.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S11.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S20.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S13.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S18.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S06.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S09.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S16.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S12.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S07.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S15.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S19.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S17.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S14.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B15.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/M13.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B17.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B01.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B05.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B11.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/M08.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/M07.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B06.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/M06.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/M12.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B03.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/M10.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B13.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B08.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/M02.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/M09.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/M11.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B16.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B12.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B18.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B19.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B04.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S03.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S08.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/B20.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/SPC.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/MPC.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/BPC.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/S01.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/M01.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/Bnan.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/Snan.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/BMnan.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/MPC .csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/Mnan.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/M03.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/Scontentieux.csv\n", "../PLESNA Compta SYSTEM/datamart/Lot/0nan.csv\n" ] } ], "source": [ "lot_path = mart_path / \"Lot\"\n", "lot_path.mkdir(exist_ok=True)\n", "for lot in df_crg[\"Lot\"].unique():\n", " df = df_crg[df_crg[\"Lot\"] == lot]\n", " dest = lot_path/f\"{lot}.csv\"\n", " print(dest)\n", " to_csv(df, dest)" ] }, { "cell_type": "markdown", "id": "4d874024-37d3-4ad2-88a0-8ab8d7e50ea3", "metadata": {}, "source": [ "## PnL" ] }, { "cell_type": "code", "execution_count": 11, "id": "ac663ab4-53cc-4574-a3a2-624703cb66b5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{2017, 2018, 2019, 2020, 2021, 2022}" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "years = set(list(df_crg[\"Année\"].unique()) + list(df_banque[\"Année\"]))\n", "years" ] }, { "cell_type": "code", "execution_count": 48, "id": "b688bfe3-3901-45c8-b9cf-22db69068716", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2017\n", "../PLESNA Compta SYSTEM/datamart/PnL/2017.csv\n", "2018\n", "../PLESNA Compta SYSTEM/datamart/PnL/2018.csv\n", "2019\n", "../PLESNA Compta SYSTEM/datamart/PnL/2019.csv\n", "2020\n", "../PLESNA Compta SYSTEM/datamart/PnL/2020.csv\n", "2021\n", "../PLESNA Compta SYSTEM/datamart/PnL/2021.csv\n", "2022\n", "../PLESNA Compta SYSTEM/datamart/PnL/2022.csv\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_187410/3027169384.py:14: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n", " df = pd.concat([df_crg, df_bq])\n", "/tmp/ipykernel_187410/3027169384.py:14: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n", " df = pd.concat([df_crg, df_bq])\n", "/tmp/ipykernel_187410/3027169384.py:14: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n", " df = pd.concat([df_crg, df_bq])\n" ] } ], "source": [ "cols = [\"Catégorie\", \"Mois\", \"Impact\"]\n", "pnl_path = mart_path / \"PnL\"\n", "pnl_path.mkdir(exist_ok=True)\n", "for year in years:\n", " print(year)\n", " try:\n", " df_crg = pd.read_csv(crg_path/f\"{year}.csv\")[cols]\n", " except FileNotFoundError:\n", " df_crg = pd.DataFrame(columns=cols)\n", " try:\n", " df_bq = pd.read_csv(banque_path/f\"{year}.csv\")[cols]\n", " except FileNotFoundError:\n", " df_bq = pd.DataFrame(columns=cols)\n", " df = pd.concat([df_crg, df_bq])\n", " #pt = pd.pivot_table(df, index=\"Catégorie\", columns=\"Mois\", aggfunc=\"sum\").fillna(0)\n", " pt = df.groupby([\"Catégorie\", \"Mois\"]).agg(\"sum\").unstack().fillna(0)\n", " pt.columns = [c[1] for c in pt.columns]\n", " pt.reset_index([\"Catégorie\"])\n", " dest = pnl_path / f\"{year}.csv\" \n", " print(dest)\n", " pt.to_csv(dest)" ] }, { "cell_type": "code", "execution_count": 14, "id": "b5ea06ef-b2d8-4706-8187-50c1f220a424", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
CatégorieMoisImpact
0Hono E/S1-80.00
1Hono E/S1-270.24
2Hono E/S1-900.08
3Hono E/S1-80.00
4Hono E/S1-145.50
\n", "
" ], "text/plain": [ " Catégorie Mois Impact\n", "0 Hono E/S 1 -80.00\n", "1 Hono E/S 1 -270.24\n", "2 Hono E/S 1 -900.08\n", "3 Hono E/S 1 -80.00\n", "4 Hono E/S 1 -145.50" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.head()" ] }, { "cell_type": "code", "execution_count": 19, "id": "7ba9caa0-8b6a-4d21-a155-c73f6535ff21", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Impact
Mois123456789101112
Catégorie
Archi-3600.00-2160.00-2880.00-480.00.000.000.000.000.000.000.000.0
Ascenseur-1723.96-114.74-1651.720.00.000.000.000.000.000.000.000.0
Assurance-6624.060.000.000.00.000.000.000.000.000.000.000.0
CCA0.002622912.98-2780000.00-100000.0-20000.000.000.000.000.000.000.000.0
Comptable0.000.00-1320.00-1200.00.00-1320.000.000.00-1320.000.000.00-1320.0
Diagnotics0.00-672.000.000.00.000.000.000.000.000.000.000.0
Eau0.00-50.520.000.00.000.000.000.000.000.000.000.0
Elec-273.74-316.06-845.500.00.000.000.000.000.000.000.000.0
Entretien-3184.22-5196.08-4516.420.00.000.000.000.000.000.000.000.0
Frais Bancaire-33.36-33.36-33.36-35.8-33.36-38.24-35.80-50.040.00-35.80-35.80-35.8
Frais Financier-2500.00-2338.06-14500.00-2500.0-2500.00-14593.38-2500.00-2500.00-14500.00-2500.00-2500.00-24044.0
Gerant0.00-2000.00-6000.002000.0-4000.00-2000.000.00-4000.00-2000.00-2000.00-2000.00-2000.0
Hono E/S-4023.24-1299.60-2574.200.00.000.000.000.000.000.000.000.0
Hono Gestion-4874.42-4742.62-7188.700.00.000.000.000.000.000.000.000.0
Loyer Charge78140.4472844.0872592.780.00.000.000.000.000.000.000.000.0
Revenue Gérance52453.0423182.848758.640.0107455.3853207.6468744.9425165.24110581.2482715.0256121.26106563.7
Solde Comptable0.000.00-136367.420.00.000.000.000.000.000.000.000.0
TF-7436.00-7436.00-7436.00-7436.0-7436.00-7436.00-7436.00-7436.00-7436.00-7436.00-2258.000.0
Travaux-4983.76-37674.84-58680.840.00.000.000.000.000.000.000.000.0
Xfert Tréso0.000.000.000.00.000.000.000.000.000.000.000.0
\n", "
" ], "text/plain": [ " Impact \\\n", "Mois 1 2 3 4 5 \n", "Catégorie \n", "Archi -3600.00 -2160.00 -2880.00 -480.0 0.00 \n", "Ascenseur -1723.96 -114.74 -1651.72 0.0 0.00 \n", "Assurance -6624.06 0.00 0.00 0.0 0.00 \n", "CCA 0.00 2622912.98 -2780000.00 -100000.0 -20000.00 \n", "Comptable 0.00 0.00 -1320.00 -1200.0 0.00 \n", "Diagnotics 0.00 -672.00 0.00 0.0 0.00 \n", "Eau 0.00 -50.52 0.00 0.0 0.00 \n", "Elec -273.74 -316.06 -845.50 0.0 0.00 \n", "Entretien -3184.22 -5196.08 -4516.42 0.0 0.00 \n", "Frais Bancaire -33.36 -33.36 -33.36 -35.8 -33.36 \n", "Frais Financier -2500.00 -2338.06 -14500.00 -2500.0 -2500.00 \n", "Gerant 0.00 -2000.00 -6000.00 2000.0 -4000.00 \n", "Hono E/S -4023.24 -1299.60 -2574.20 0.0 0.00 \n", "Hono Gestion -4874.42 -4742.62 -7188.70 0.0 0.00 \n", "Loyer Charge 78140.44 72844.08 72592.78 0.0 0.00 \n", "Revenue Gérance 52453.04 23182.84 8758.64 0.0 107455.38 \n", "Solde Comptable 0.00 0.00 -136367.42 0.0 0.00 \n", "TF -7436.00 -7436.00 -7436.00 -7436.0 -7436.00 \n", "Travaux -4983.76 -37674.84 -58680.84 0.0 0.00 \n", "Xfert Tréso 0.00 0.00 0.00 0.0 0.00 \n", "\n", " \\\n", "Mois 6 7 8 9 10 11 \n", "Catégorie \n", "Archi 0.00 0.00 0.00 0.00 0.00 0.00 \n", "Ascenseur 0.00 0.00 0.00 0.00 0.00 0.00 \n", "Assurance 0.00 0.00 0.00 0.00 0.00 0.00 \n", "CCA 0.00 0.00 0.00 0.00 0.00 0.00 \n", "Comptable -1320.00 0.00 0.00 -1320.00 0.00 0.00 \n", "Diagnotics 0.00 0.00 0.00 0.00 0.00 0.00 \n", "Eau 0.00 0.00 0.00 0.00 0.00 0.00 \n", "Elec 0.00 0.00 0.00 0.00 0.00 0.00 \n", "Entretien 0.00 0.00 0.00 0.00 0.00 0.00 \n", "Frais Bancaire -38.24 -35.80 -50.04 0.00 -35.80 -35.80 \n", "Frais Financier -14593.38 -2500.00 -2500.00 -14500.00 -2500.00 -2500.00 \n", "Gerant -2000.00 0.00 -4000.00 -2000.00 -2000.00 -2000.00 \n", "Hono E/S 0.00 0.00 0.00 0.00 0.00 0.00 \n", "Hono Gestion 0.00 0.00 0.00 0.00 0.00 0.00 \n", "Loyer Charge 0.00 0.00 0.00 0.00 0.00 0.00 \n", "Revenue Gérance 53207.64 68744.94 25165.24 110581.24 82715.02 56121.26 \n", "Solde Comptable 0.00 0.00 0.00 0.00 0.00 0.00 \n", "TF -7436.00 -7436.00 -7436.00 -7436.00 -7436.00 -2258.00 \n", "Travaux 0.00 0.00 0.00 0.00 0.00 0.00 \n", "Xfert Tréso 0.00 0.00 0.00 0.00 0.00 0.00 \n", "\n", " \n", "Mois 12 \n", "Catégorie \n", "Archi 0.0 \n", "Ascenseur 0.0 \n", "Assurance 0.0 \n", "CCA 0.0 \n", "Comptable -1320.0 \n", "Diagnotics 0.0 \n", "Eau 0.0 \n", "Elec 0.0 \n", "Entretien 0.0 \n", "Frais Bancaire -35.8 \n", "Frais Financier -24044.0 \n", "Gerant -2000.0 \n", "Hono E/S 0.0 \n", "Hono Gestion 0.0 \n", "Loyer Charge 0.0 \n", "Revenue Gérance 106563.7 \n", "Solde Comptable 0.0 \n", "TF 0.0 \n", "Travaux 0.0 \n", "Xfert Tréso 0.0 " ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pt = pd.pivot_table(df, index=\"Catégorie\", columns=\"Mois\", aggfunc=\"sum\").fillna(0)\n", "pt" ] }, { "cell_type": "code", "execution_count": 45, "id": "5e3d01a2-93d4-4b5e-84df-3e3cfda5eabd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MultiIndex([('Impact', 1),\n", " ('Impact', 2),\n", " ('Impact', 3),\n", " ('Impact', 4),\n", " ('Impact', 5),\n", " ('Impact', 6),\n", " ('Impact', 7),\n", " ('Impact', 8),\n", " ('Impact', 9),\n", " ('Impact', 10),\n", " ('Impact', 11),\n", " ('Impact', 12)],\n", " names=[None, 'Mois'])" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pt = df.groupby([\"Catégorie\", \"Mois\"]).agg(\"sum\").unstack().fillna(0)\n", "pt.columns" ] }, { "cell_type": "code", "execution_count": 46, "id": "48720528-7d29-432e-9019-cb1b11c6e399", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Catégorie123456789101112
0Archi-3600.00-2160.00-2880.00-480.00.000.000.000.000.000.000.000.0
1Ascenseur-1723.96-114.74-1651.720.00.000.000.000.000.000.000.000.0
2Assurance-6624.060.000.000.00.000.000.000.000.000.000.000.0
3CCA0.002622912.98-2780000.00-100000.0-20000.000.000.000.000.000.000.000.0
4Comptable0.000.00-1320.00-1200.00.00-1320.000.000.00-1320.000.000.00-1320.0
5Diagnotics0.00-672.000.000.00.000.000.000.000.000.000.000.0
6Eau0.00-50.520.000.00.000.000.000.000.000.000.000.0
7Elec-273.74-316.06-845.500.00.000.000.000.000.000.000.000.0
8Entretien-3184.22-5196.08-4516.420.00.000.000.000.000.000.000.000.0
9Frais Bancaire-33.36-33.36-33.36-35.8-33.36-38.24-35.80-50.040.00-35.80-35.80-35.8
10Frais Financier-2500.00-2338.06-14500.00-2500.0-2500.00-14593.38-2500.00-2500.00-14500.00-2500.00-2500.00-24044.0
11Gerant0.00-2000.00-6000.002000.0-4000.00-2000.000.00-4000.00-2000.00-2000.00-2000.00-2000.0
12Hono E/S-4023.24-1299.60-2574.200.00.000.000.000.000.000.000.000.0
13Hono Gestion-4874.42-4742.62-7188.700.00.000.000.000.000.000.000.000.0
14Loyer Charge78140.4472844.0872592.780.00.000.000.000.000.000.000.000.0
15Revenue Gérance52453.0423182.848758.640.0107455.3853207.6468744.9425165.24110581.2482715.0256121.26106563.7
16Solde Comptable0.000.00-136367.420.00.000.000.000.000.000.000.000.0
17TF-7436.00-7436.00-7436.00-7436.0-7436.00-7436.00-7436.00-7436.00-7436.00-7436.00-2258.000.0
18Travaux-4983.76-37674.84-58680.840.00.000.000.000.000.000.000.000.0
19Xfert Tréso0.000.000.000.00.000.000.000.000.000.000.000.0
\n", "
" ], "text/plain": [ " Catégorie 1 2 3 4 5 \\\n", "0 Archi -3600.00 -2160.00 -2880.00 -480.0 0.00 \n", "1 Ascenseur -1723.96 -114.74 -1651.72 0.0 0.00 \n", "2 Assurance -6624.06 0.00 0.00 0.0 0.00 \n", "3 CCA 0.00 2622912.98 -2780000.00 -100000.0 -20000.00 \n", "4 Comptable 0.00 0.00 -1320.00 -1200.0 0.00 \n", "5 Diagnotics 0.00 -672.00 0.00 0.0 0.00 \n", "6 Eau 0.00 -50.52 0.00 0.0 0.00 \n", "7 Elec -273.74 -316.06 -845.50 0.0 0.00 \n", "8 Entretien -3184.22 -5196.08 -4516.42 0.0 0.00 \n", "9 Frais Bancaire -33.36 -33.36 -33.36 -35.8 -33.36 \n", "10 Frais Financier -2500.00 -2338.06 -14500.00 -2500.0 -2500.00 \n", "11 Gerant 0.00 -2000.00 -6000.00 2000.0 -4000.00 \n", "12 Hono E/S -4023.24 -1299.60 -2574.20 0.0 0.00 \n", "13 Hono Gestion -4874.42 -4742.62 -7188.70 0.0 0.00 \n", "14 Loyer Charge 78140.44 72844.08 72592.78 0.0 0.00 \n", "15 Revenue Gérance 52453.04 23182.84 8758.64 0.0 107455.38 \n", "16 Solde Comptable 0.00 0.00 -136367.42 0.0 0.00 \n", "17 TF -7436.00 -7436.00 -7436.00 -7436.0 -7436.00 \n", "18 Travaux -4983.76 -37674.84 -58680.84 0.0 0.00 \n", "19 Xfert Tréso 0.00 0.00 0.00 0.0 0.00 \n", "\n", " 6 7 8 9 10 11 12 \n", "0 0.00 0.00 0.00 0.00 0.00 0.00 0.0 \n", "1 0.00 0.00 0.00 0.00 0.00 0.00 0.0 \n", "2 0.00 0.00 0.00 0.00 0.00 0.00 0.0 \n", "3 0.00 0.00 0.00 0.00 0.00 0.00 0.0 \n", "4 -1320.00 0.00 0.00 -1320.00 0.00 0.00 -1320.0 \n", "5 0.00 0.00 0.00 0.00 0.00 0.00 0.0 \n", "6 0.00 0.00 0.00 0.00 0.00 0.00 0.0 \n", "7 0.00 0.00 0.00 0.00 0.00 0.00 0.0 \n", "8 0.00 0.00 0.00 0.00 0.00 0.00 0.0 \n", "9 -38.24 -35.80 -50.04 0.00 -35.80 -35.80 -35.8 \n", "10 -14593.38 -2500.00 -2500.00 -14500.00 -2500.00 -2500.00 -24044.0 \n", "11 -2000.00 0.00 -4000.00 -2000.00 -2000.00 -2000.00 -2000.0 \n", "12 0.00 0.00 0.00 0.00 0.00 0.00 0.0 \n", "13 0.00 0.00 0.00 0.00 0.00 0.00 0.0 \n", "14 0.00 0.00 0.00 0.00 0.00 0.00 0.0 \n", "15 53207.64 68744.94 25165.24 110581.24 82715.02 56121.26 106563.7 \n", "16 0.00 0.00 0.00 0.00 0.00 0.00 0.0 \n", "17 -7436.00 -7436.00 -7436.00 -7436.00 -7436.00 -2258.00 0.0 \n", "18 0.00 0.00 0.00 0.00 0.00 0.00 0.0 \n", "19 0.00 0.00 0.00 0.00 0.00 0.00 0.0 " ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pt.columns = [c[1] for c in pt.columns]\n", "pt.reset_index([\"Catégorie\"])" ] }, { "cell_type": "code", "execution_count": 47, "id": "43202565-7645-445e-b7be-750c1c16d7ab", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['Archi', 'Ascenseur', 'Assurance', 'CCA', 'Comptable', 'Diagnotics',\n", " 'Eau', 'Elec', 'Entretien', 'Frais Bancaire', 'Frais Financier',\n", " 'Gerant', 'Hono E/S', 'Hono Gestion', 'Loyer Charge', 'Revenue Gérance',\n", " 'Solde Comptable', 'TF', 'Travaux', 'Xfert Tréso'],\n", " dtype='object', name='Catégorie')" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pt.index" ] }, { "cell_type": "code", "execution_count": null, "id": "3cc60d28-d4ef-416b-a2a4-ecdc472f411c", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.6" } }, "nbformat": 4, "nbformat_minor": 5 }