CSV manipulation

CSV manipulation provided for continents on csv
This commit is contained in:
bennteaa 2025-05-20 19:54:27 +10:00
parent f1ed754b3d
commit a49cc771b8
2 changed files with 68 additions and 0 deletions

BIN
.DS_Store vendored

Binary file not shown.

68
ContinentsPHS.ipynb Normal file
View file

@ -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
}