{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CSV file saved as 'C:\\Users\\fuentesm\\Marilu\\Deltares\\Projects\\Coastviewer\\kustlijnkaartenboek\\raw\\tkl2023.csv'\n" ] } ], "source": [ "# Create TKL file from previous years\n", "import os\n", "import pandas as pd\n", "\n", "def merge_csv_files(folder_path):\n", " # Get a list of all CSV files in the specified folder\n", " csv_files = [file for file in os.listdir(folder_path) if file.endswith('.csv')]\n", "\n", " # Check if there are any CSV files in the folder\n", " if not csv_files:\n", " print(\"No CSV files found in the specified folder.\")\n", " return None\n", "\n", " # Initialize an empty DataFrame to store the merged data\n", " merged_data = pd.DataFrame()\n", "\n", " # Loop through each CSV file and merge it into the DataFrame\n", " for csv_file in csv_files:\n", " file_path = os.path.join(folder_path, csv_file)\n", " df = pd.read_csv(file_path, sep=';', usecols=['Kustvak', 'Raai', 'BKL','TKL [m + RSP]','Landwaartse grens [m + RSP]','Trend [m/jaar]'], skiprows=[1, 2, 3,4])\n", " merged_data = pd.concat([merged_data, df], ignore_index=True)\n", "\n", " return merged_data\n", "\n", "# Specify the folder path containing CSV files\n", "folder_path = r'C:\\Users\\fuentesm\\Marilu\\Deltares\\Projects\\Coastviewer\\kustlijnkaartenboek\\raw\\TKL2022'\n", "\n", "# Call the function to merge CSV files\n", "merged_dataset = merge_csv_files(folder_path)\n", "\n", "# Display the merged dataset\n", "# print(merged_dataset.head())\n", "merged_dataset = merged_dataset[['Kustvak', 'Raai', 'BKL','TKL [m + RSP]','Landwaartse grens [m + RSP]','Trend [m/jaar]']]\n", "merged_dataset = merged_dataset.rename(columns={'TKL [m + RSP]':'TKL 2023','Landwaartse grens [m + RSP]': 'NA', 'Trend [m/jaar]': 'Trend 2023'})\n", "merged_dataset[50:100]\n", "\n", "# Save the dataset as CSV\n", "csv_filename = r'C:\\Users\\fuentesm\\Marilu\\Deltares\\Projects\\Coastviewer\\kustlijnkaartenboek\\raw\\tkl2023.csv'\n", "merged_dataset.to_csv(csv_filename, index=False)\n", "print(f\"CSV file saved as '{csv_filename}'\")\n", "\n", "# Save the dataset as Excel (XLSX)\n", "excel_filename = r'C:\\Users\\fuentesm\\Marilu\\Deltares\\Projects\\Coastviewer\\kustlijnkaartenboek\\raw\\tkl2023.xlsx'\n", "merged_dataset.to_excel(excel_filename, index=False)\n", "\n", "# Save the merged dataset to a new CSV file if needed\n", "# merged_dataset.to_csv('path/to/save/merged_dataset.csv', index=Fal" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(r'C:\\Users\\fuentesm\\Marilu\\Deltares\\Projects\\Coastviewer\\kustlijnkaartenboek\\raw\\TKL2022\\02_Schiermonnikoog_TKL_resultaten_BKL_1-1-2023.csv', sep=';', usecols=['Kustvak', 'Raai', 'BKL','TKL [m + RSP]','Landwaartse grens [m + RSP]','Trend [m/jaar]'], skiprows=[1, 2, 3,4])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "df = df[['Kustvak','Raai']]" ] }, { "cell_type": "code", "execution_count": null, "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", "
KustvakRaaiBKLTKL [m + RSP]
02100.0725.02387.33
12101.0705.02242.22
22102.0700.02142.46
32103.0689.02020.84
42104.0694.01930.57
...............
622960.0283.0726.35
632980.0267.0739.62
6421000.0257.0759.52
6521020.0252.0778.71
6621040.0200.0794.45
\n", "

67 rows × 4 columns

\n", "
" ], "text/plain": [ " Kustvak Raai BKL TKL [m + RSP]\n", "0 2 100.0 725.0 2387.33\n", "1 2 101.0 705.0 2242.22\n", "2 2 102.0 700.0 2142.46\n", "3 2 103.0 689.0 2020.84\n", "4 2 104.0 694.0 1930.57\n", ".. ... ... ... ...\n", "62 2 960.0 283.0 726.35\n", "63 2 980.0 267.0 739.62\n", "64 2 1000.0 257.0 759.52\n", "65 2 1020.0 252.0 778.71\n", "66 2 1040.0 200.0 794.45\n", "\n", "[67 rows x 4 columns]" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] } ], "metadata": { "kernelspec": { "display_name": "coastviewer", "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.10.13" } }, "nbformat": 4, "nbformat_minor": 2 }