{ "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", " | Kustvak | \n", "Raai | \n", "BKL | \n", "TKL [m + RSP] | \n", "
---|---|---|---|---|
0 | \n", "2 | \n", "100.0 | \n", "725.0 | \n", "2387.33 | \n", "
1 | \n", "2 | \n", "101.0 | \n", "705.0 | \n", "2242.22 | \n", "
2 | \n", "2 | \n", "102.0 | \n", "700.0 | \n", "2142.46 | \n", "
3 | \n", "2 | \n", "103.0 | \n", "689.0 | \n", "2020.84 | \n", "
4 | \n", "2 | \n", "104.0 | \n", "694.0 | \n", "1930.57 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
62 | \n", "2 | \n", "960.0 | \n", "283.0 | \n", "726.35 | \n", "
63 | \n", "2 | \n", "980.0 | \n", "267.0 | \n", "739.62 | \n", "
64 | \n", "2 | \n", "1000.0 | \n", "257.0 | \n", "759.52 | \n", "
65 | \n", "2 | \n", "1020.0 | \n", "252.0 | \n", "778.71 | \n", "
66 | \n", "2 | \n", "1040.0 | \n", "200.0 | \n", "794.45 | \n", "
67 rows × 4 columns
\n", "