Created
March 11, 2024 02:03
-
-
Save bennyistanto/5400d149897a313b7b1c9150c252da6f to your computer and use it in GitHub Desktop.
Convert DBF from ArcPy Zonal Histogram, transpose column and save as CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "fba5bc85", | |
"metadata": {}, | |
"source": [ | |
"# Convert DBF from ArcPy Zonal Histogram, transpose column and save as CSV" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "9867b01b", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Columns in the DBF file: ['LABEL', 'TUR', 'geometry']\n" | |
] | |
} | |
], | |
"source": [ | |
"import os\n", | |
"import geopandas as gpd\n", | |
"\n", | |
"# Inspecting the columns of one of the uploaded DBF files\n", | |
"sample_dbf_path = '/mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/dbf/tur_pheno_2003_eos_season2.dbf'\n", | |
"\n", | |
"# Read the DBF file using Geopandas\n", | |
"try:\n", | |
" sample_df = gpd.read_file(sample_dbf_path)\n", | |
" # Display the columns of the DataFrame\n", | |
" print(\"Columns in the DBF file:\", sample_df.columns.tolist())\n", | |
"except Exception as e:\n", | |
" print(f\"Error reading file {os.path.basename(sample_dbf_path)}: {e}\")\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "b0e108f4", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>ID</th>\n", | |
" <th>adm0_src</th>\n", | |
" <th>adm0_name</th>\n", | |
" <th>1</th>\n", | |
" <th>2</th>\n", | |
" <th>3</th>\n", | |
" <th>4</th>\n", | |
" <th>5</th>\n", | |
" <th>6</th>\n", | |
" <th>7</th>\n", | |
" <th>8</th>\n", | |
" <th>9</th>\n", | |
" <th>10</th>\n", | |
" <th>11</th>\n", | |
" <th>12</th>\n", | |
" <th>geometry</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>0</td>\n", | |
" <td>TUR</td>\n", | |
" <td>Turkey</td>\n", | |
" <td>963563</td>\n", | |
" <td>11435811</td>\n", | |
" <td>20721975</td>\n", | |
" <td>19904284</td>\n", | |
" <td>180894793</td>\n", | |
" <td>584078536</td>\n", | |
" <td>510101623</td>\n", | |
" <td>412091697</td>\n", | |
" <td>167236249</td>\n", | |
" <td>157152795</td>\n", | |
" <td>190062235</td>\n", | |
" <td>167058743</td>\n", | |
" <td>None</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" ID adm0_src adm0_name 1 2 3 4 5 \\\n", | |
"0 0 TUR Turkey 963563 11435811 20721975 19904284 180894793 \n", | |
"\n", | |
" 6 7 8 9 10 11 \\\n", | |
"0 584078536 510101623 412091697 167236249 157152795 190062235 \n", | |
"\n", | |
" 12 geometry \n", | |
"0 167058743 None " | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import pandas as pd\n", | |
"import geopandas as gpd\n", | |
"\n", | |
"def process_dbf_file(file_path):\n", | |
" try:\n", | |
" # Read the DBF file using Geopandas\n", | |
" df = gpd.read_file(file_path)\n", | |
"\n", | |
" # Check if 'LABEL' and 'SYR' columns are present\n", | |
" if 'LABEL' not in df.columns or 'TUR' not in df.columns:\n", | |
" raise ValueError(\"Required columns 'LABEL' or 'TUR' not found in the file\")\n", | |
"\n", | |
" # Creating a dictionary to hold the sums for each label\n", | |
" data = {str(i): 0 for i in range(1, 13)}\n", | |
"\n", | |
" # Summing up the values for each label\n", | |
" for _, row in df.iterrows():\n", | |
" label = str(row['LABEL'])\n", | |
" if label in data:\n", | |
" data[label] += row['TUR']\n", | |
"\n", | |
" # Creating a DataFrame\n", | |
" result_df = pd.DataFrame([data])\n", | |
" result_df.insert(0, 'adm0_name', 'Turkey')\n", | |
" result_df.insert(0, 'adm0_src', 'TUR')\n", | |
" result_df.insert(0, 'ID', 0)\n", | |
" result_df['geometry'] = None\n", | |
"\n", | |
" return result_df\n", | |
"\n", | |
" except Exception as e:\n", | |
" print(f\"Error processing file {os.path.basename(file_path)}: {e}\")\n", | |
" return None\n", | |
"\n", | |
"# Define path to the DBF file\n", | |
"dbf_file_path = '/mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/dbf/tur_pheno_2003_eos_season1.dbf'\n", | |
"\n", | |
"# Process the DBF file and display the result\n", | |
"processed_df = process_dbf_file(dbf_file_path)\n", | |
"processed_df\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "5c8fb384", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2003_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2003_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2003_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2003_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2004_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2004_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2004_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2004_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2005_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2005_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2005_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2005_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2006_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2006_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2006_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2006_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2007_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2007_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2007_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2007_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2008_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2008_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2008_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2008_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2009_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2009_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2009_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2009_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2010_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2010_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2010_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2010_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2011_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2011_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2011_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2011_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2012_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2012_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2012_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2012_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2013_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2013_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2013_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2013_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2014_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2014_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2014_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2014_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2015_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2015_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2015_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2015_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2016_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2016_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2016_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2016_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2017_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2017_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2017_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2017_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2018_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2018_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2018_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2018_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2019_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2019_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2019_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2019_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2020_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2020_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2020_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2020_sos_season2.csv\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2021_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2021_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2021_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2021_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2022_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2022_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2022_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2022_sos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2023_eos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2023_eos_season2.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2023_sos_season1.csv\n", | |
"Processed and saved: /mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/tur_pheno_2023_sos_season2.csv\n" | |
] | |
} | |
], | |
"source": [ | |
"import os\n", | |
"import pandas as pd\n", | |
"import geopandas as gpd\n", | |
"\n", | |
"def process_dbf_file(file_path):\n", | |
" try:\n", | |
" # Read the DBF file using Geopandas\n", | |
" df = gpd.read_file(file_path)\n", | |
"\n", | |
" # Check if 'LABEL' and 'SYR' columns are present\n", | |
" if 'LABEL' not in df.columns or 'TUR' not in df.columns:\n", | |
" raise ValueError(\"Required columns 'LABEL' or 'TUR' not found in the file\")\n", | |
"\n", | |
" # Initialize a dictionary for data aggregation\n", | |
" data = {str(i): 0 for i in range(1, 13)}\n", | |
"\n", | |
" # Summing up the values for each label\n", | |
" for _, row in df.iterrows():\n", | |
" label = str(row['LABEL'])\n", | |
" if label in data:\n", | |
" data[label] += row['TUR']\n", | |
"\n", | |
" # Creating a DataFrame\n", | |
" result_df = pd.DataFrame([data])\n", | |
" result_df.insert(0, 'geometry', None) # Assuming geometry is not needed\n", | |
" result_df.insert(0, 'adm0_name', 'Turkey')\n", | |
" result_df.insert(0, 'adm0_src', 'TUR')\n", | |
" result_df.insert(0, 'ID', 0)\n", | |
"\n", | |
" return result_df\n", | |
"\n", | |
" except Exception as e:\n", | |
" print(f\"Error processing file {os.path.basename(file_path)}: {e}\")\n", | |
" return None\n", | |
"\n", | |
"def process_all_dbf_files(input_folder, output_folder):\n", | |
" # List all .dbf files in the folder\n", | |
" dbf_files = [f for f in os.listdir(input_folder) if f.lower().endswith('.dbf')]\n", | |
"\n", | |
" for dbf_file in dbf_files:\n", | |
" dbf_file_path = os.path.join(input_folder, dbf_file)\n", | |
" processed_df = process_dbf_file(dbf_file_path)\n", | |
"\n", | |
" if processed_df is not None:\n", | |
" # Save the processed DataFrame to a CSV file\n", | |
" csv_file_path = os.path.join(output_folder, os.path.splitext(dbf_file)[0] + '.csv')\n", | |
" processed_df.to_csv(csv_file_path, index=False)\n", | |
" print(f\"Processed and saved: {csv_file_path}\")\n", | |
"\n", | |
"# Define input and output folder paths\n", | |
"input_folder = '/mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0/dbf' # Folder containing DBF files\n", | |
"output_folder = '/mnt/x/Temp/modis/tur/gee/11_timesat_raw/geotiff/step06_zonalhist/adm0' # Folder to save CSV files\n", | |
"\n", | |
"# Ensure output folder exists\n", | |
"if not os.path.exists(output_folder):\n", | |
" os.makedirs(output_folder)\n", | |
"\n", | |
"# Process all DBF files in the input folder\n", | |
"process_all_dbf_files(input_folder, output_folder)\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "1cd0a2ab", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"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.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment