From a49cc771b861e1b338b71f26e0aec3b329ccead8 Mon Sep 17 00:00:00 2001 From: bennteaa <104936549@student.swin.edu.au> Date: Tue, 20 May 2025 19:54:27 +1000 Subject: [PATCH] CSV manipulation CSV manipulation provided for continents on csv --- .DS_Store | Bin 6148 -> 6148 bytes ContinentsPHS.ipynb | 68 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 ContinentsPHS.ipynb diff --git a/.DS_Store b/.DS_Store index abe74b03b70a06cbde227e6efebaac370933a512..85e7f17f5666fd114a85f52fe1f4c185f81a6d73 100644 GIT binary patch delta 41 xcmZoMXfc@J&&akhU^gQ-8v_FaGlMfjFhlTUF(&!V-b{N~CpL&}X6N|J4*=9G3W)#! delta 58 zcmZoMXfc@J&&a+pU^gQ-I|Bm)Gea^%F+=fWF(!FoD7!4UC@&{JFC8e$xY>wlKkH_8 Hj=%f>mt_uT diff --git a/ContinentsPHS.ipynb b/ContinentsPHS.ipynb new file mode 100644 index 0000000..9942f53 --- /dev/null +++ b/ContinentsPHS.ipynb @@ -0,0 +1,68 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "31c78300-b0ea-4e03-979f-b8f12a55a4df", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "\n", + "# Load your CSV\n", + "df = pd.read_csv(\"FilteredPHSbySES.csv\")\n", + "\n", + "# Define full mapping\n", + "country_to_continent = {\n", + " 'POL': 'Europe', 'NZL': 'Oceania', 'FRA': 'Europe', 'USA': 'North America', 'CAN': 'North America',\n", + " 'AUS': 'Oceania', 'JPN': 'Asia', 'KOR': 'Asia', 'MEX': 'North America', 'CHL': 'South America',\n", + " 'DEU': 'Europe', 'ITA': 'Europe', 'ESP': 'Europe', 'SWE': 'Europe', 'NOR': 'Europe', 'DNK': 'Europe',\n", + " 'FIN': 'Europe', 'NLD': 'Europe', 'BEL': 'Europe', 'CHE': 'Europe', 'GBR': 'Europe', 'IRL': 'Europe',\n", + " 'AUT': 'Europe', 'COL': 'South America', 'SVK': 'Europe', 'GRC': 'Europe', 'TUR': 'Europe',\n", + " 'HUN': 'Europe', 'LTU': 'Europe', 'CZE': 'Europe', 'EST': 'Europe', 'HRV': 'Europe', 'SVN': 'Europe',\n", + " 'BGR': 'Europe', 'PRT': 'Europe', 'LVA': 'Europe', 'ISR': 'Asia', 'LUX': 'Europe', 'ROU': 'Europe',\n", + " 'ISL': 'Europe'\n", + "}\n", + "\n", + "# Update the ACTION column with continent mapping, then rename to CONTINENT\n", + "if 'ACTION' in df.columns:\n", + " df['ACTION'] = df['REF_AREA'].map(country_to_continent)\n", + " df.rename(columns={'ACTION': 'CONTINENT'}, inplace=True)\n", + "else:\n", + " df['CONTINENT'] = df['REF_AREA'].map(country_to_continent)\n", + "\n", + "# Save the updated file if needed\n", + "df.to_csv(\"PHSwithContinent.csv\", index=False)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c29ebc0a-0d73-4541-b860-fec52aef9561", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:base] *", + "language": "python", + "name": "conda-base-py" + }, + "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.12.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}