Skip to content

Commit

Permalink
fix: excel rework + add author
Browse files Browse the repository at this point in the history
  • Loading branch information
fravenel committed Feb 22, 2022
1 parent 5cd4074 commit 8f03599
Show file tree
Hide file tree
Showing 3 changed files with 406 additions and 141 deletions.
198 changes: 131 additions & 67 deletions Excel/Excel_Consolidate_files.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "tribal-wyoming",
"id": "tropical-breakfast",
"metadata": {
"papermill": {},
"tags": []
Expand All @@ -13,178 +13,242 @@
},
{
"cell_type": "markdown",
"id": "elect-lover",
"id": "danish-allergy",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"# Excel - Consolidate files\n",
"<a href=\"https://app.naas.ai/user-redirect/naas/downloader?url=https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/Excel/Excel_Consolidate_files.ipynb\" target=\"_parent\"><img src=\"https://naasai-public.s3.eu-west-3.amazonaws.com/open_in_naas.svg\"/></a>"
"# Excel - Consolidate data in one sheet\n",
"<a href=\"https://app.naas.ai/user-redirect/naas/downloader?url=https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/Excel/Excel_Read_file.ipynb\" target=\"_parent\"><img src=\"https://naasai-public.s3.eu-west-3.amazonaws.com/open_in_naas.svg\"/></a>"
]
},
{
"cell_type": "markdown",
"id": "bb2e5fbb-fdab-4da1-8aa2-e743abd5a085",
"id": "978e5e32-8839-4b39-abb7-f5e8bda9f313",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Tags:** #excel #pandas #concat"
"**Tags:** #excel #pandas #read #save #naas #asset"
]
},
{
"cell_type": "markdown",
"id": "weird-currency",
"id": "1bf0834d-3a8e-4f4a-98ee-fdbcc2ee650f",
"metadata": {},
"source": [
"**Author:** [Florent Ravenel](https://www.linkedin.com/in/ACoAABCNSioBW3YZHc2lBHVG0E_TXYWitQkmwog/)"
]
},
{
"cell_type": "markdown",
"id": "surgical-birmingham",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Read file 1 "
"## Input"
]
},
{
"cell_type": "markdown",
"id": "2112a917-9ba5-4ed3-b7c1-f204f0aca263",
"metadata": {},
"source": [
"### Import libraries"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "visible-binding",
"execution_count": null,
"id": "f7876579-4803-4130-b095-497225f417f7",
"metadata": {
"execution": {
"iopub.execute_input": "2021-01-26T14:47:55.684883Z",
"iopub.status.busy": "2021-01-26T14:47:55.684607Z",
"iopub.status.idle": "2021-01-26T14:47:57.921894Z",
"shell.execute_reply": "2021-01-26T14:47:57.921351Z",
"shell.execute_reply.started": "2021-01-26T14:47:55.684817Z"
},
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"import pandas as pd \n",
"\n",
"data1 = pd.read_excel(\"Excel-Sales_Jan2020.xlsx\")\n",
"data1"
"import pandas as pd\n",
"import naas"
]
},
{
"cell_type": "markdown",
"id": "freelance-venture",
"metadata": {
"papermill": {},
"tags": []
},
"id": "6ae0fb10-e3c2-4ced-bd32-c2112195dc24",
"metadata": {},
"source": [
"## Read file 2"
"### Variables"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "express-exhibition",
"execution_count": null,
"id": "0e204bc4-efbf-4dc5-b947-9fe568724fc6",
"metadata": {},
"outputs": [],
"source": [
"# Input\n",
"excel_file_path1 = \"Excel-Sales_Jan2020.xlsx\"\n",
"excel_file_path2 = \"Excel-Sales_Jan2020.xlsx\"\n",
"\n",
"# Output\n",
"excel_output_path = \"Conso.xlsx\""
]
},
{
"cell_type": "markdown",
"id": "4b24dceb-ed1e-4af9-af4e-48f592e2438b",
"metadata": {},
"source": [
"## Model"
]
},
{
"cell_type": "markdown",
"id": "656610e2-5595-429c-ae1e-ccb1d32671d7",
"metadata": {},
"source": [
"### Read the 2 Excel files"
]
},
{
"cell_type": "markdown",
"id": "f08eea54-87b0-4aba-8c5a-2a856c9ed8ca",
"metadata": {
"papermill": {},
"execution": {
"iopub.execute_input": "2022-02-22T07:35:00.624021Z",
"iopub.status.busy": "2022-02-22T07:35:00.623743Z",
"iopub.status.idle": "2022-02-22T07:35:00.632235Z",
"shell.execute_reply": "2022-02-22T07:35:00.631300Z",
"shell.execute_reply.started": "2022-02-22T07:35:00.623996Z"
},
"tags": []
},
"outputs": [],
"source": [
"data2 = pd.read_excel(\"Excel-Sales_Feb2020.xlsx\")\n",
"data2"
"You want to add more parameters ?<br>\n",
"👉 Check out the pandas documentation <a href=\"https://pandas.pydata.org/docs/reference/api/pandas.read_excel.html\">here</a>."
]
},
{
"cell_type": "markdown",
"id": "signal-sterling",
"cell_type": "code",
"execution_count": null,
"id": "hawaiian-consortium",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"## Consolidate files"
"df1 = pd.read_excel(excel_file_path1)\n",
"df1"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "expected-apollo",
"execution_count": null,
"id": "8c49069f-527a-48bb-a64d-0ffd4f6a43d9",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"data = pd.concat([data1,data2],axis=0)\n",
"data"
"df2 = pd.read_excel(excel_file_path2)\n",
"df2"
]
},
{
"cell_type": "markdown",
"id": "written-projection",
"id": "5f920cc5-720c-41bf-8f25-9781c749bb7d",
"metadata": {
"papermill": {},
"execution": {
"iopub.execute_input": "2022-02-22T07:45:54.739735Z",
"iopub.status.busy": "2022-02-22T07:45:54.739510Z",
"iopub.status.idle": "2022-02-22T07:45:54.742268Z",
"shell.execute_reply": "2022-02-22T07:45:54.741637Z",
"shell.execute_reply.started": "2022-02-22T07:45:54.739712Z"
},
"tags": []
},
"source": [
"## Export consolidated file "
"### Consolidate Excel"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "negative-cradle",
"execution_count": null,
"id": "021bf550-bdb4-4951-8c78-4a1a40e959b5",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"data.to_excel(\"Conso.xlsx\")"
"df_concat = pd.concat([df1, df2], axis=0).reset_index(drop=True)\n",
"df_concat"
]
},
{
"cell_type": "markdown",
"id": "experienced-bleeding",
"id": "expired-target",
"metadata": {
"execution": {
"iopub.execute_input": "2021-01-26T14:49:22.992682Z",
"iopub.status.busy": "2021-01-26T14:49:22.992460Z",
"iopub.status.idle": "2021-01-26T14:49:22.995432Z",
"shell.execute_reply": "2021-01-26T14:49:22.994789Z",
"shell.execute_reply.started": "2021-01-26T14:49:22.992660Z"
},
"papermill": {},
"tags": []
},
"source": [
"## Create a shareable link"
"## Output"
]
},
{
"cell_type": "markdown",
"id": "6a76ae5d-9117-420f-84f4-49ab28e4a8f3",
"metadata": {},
"source": [
"### Save dataframe to Excel"
]
},
{
"cell_type": "markdown",
"id": "d74b94f6-f41a-4eeb-a5c8-3a641cc8ccfb",
"metadata": {},
"source": [
"You want to add more parameters ?<br>\n",
"👉 Check out the pandas documentation <a href=\"https://pandas.pydata.org/docs/reference/api/pandas.read_excel.html\">here</a>."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "regional-liechtenstein",
"execution_count": null,
"id": "agreed-correspondence",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"import naas \n",
"\n",
"naas.assets.add(\"Conso.xlsx\")"
"df_concat.to_excel(excel_output_path)\n",
"print(f'💾 Excel {excel_output_path} successfully saved in Naas.')"
]
},
{
"cell_type": "markdown",
"id": "79104f6b-600f-4903-910e-8123b78976fb",
"metadata": {},
"source": [
"### Share excel with Naas"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "electoral-press",
"id": "d3e14a28-07cd-4f29-9aa9-a289ea4a4f6c",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": []
"source": [
"naas.asset.add(excel_output_path)"
]
}
],
"metadata": {
Expand Down Expand Up @@ -214,4 +278,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
Loading

0 comments on commit 8f03599

Please sign in to comment.