This project processes electoral data for the Órgano Deliberativo Departamental (ODD) and Órgano Deliberativo Nacional (ODN) in Uruguay. It provides a set of tools to clean, transform, and analyze voting data for different departments.
- Data Sources
- Project Structure
- Data Processing Steps
- Output Files
- Setup and Usage
- Adding New Departments
- GeoJSON Processing
- Dependencies
- Credits
The project uses the following data sources:
- Excel files containing ODD data located in
data/raw/results/ODD
- Excel files containing ODN data located in
data/raw/results/ODN
- JSON files for mapping series to zones located in
maps/zonasxseries
The project consists of the following key components:
-
Jupyter notebooks for data processing:
notebooks/ODD/data_processing_notebook_ODD.ipynb
: Processes ODD data for all departmentsnotebooks/ODN/data_processing_notebook_ODN.ipynb
: Processes ODN data for all departmentsnotebooks/mapas/add_zones_to_geojson.ipynb
: Adds zone information to GeoJSON files
-
Python scripts for GeoJSON preparation:
scripts/convert_to_geojson_by_depto.py
: Converts the original shapefile to separate GeoJSON files for each departmentscripts/convert_to_geojson.py
: Converts the original shapefile to a single GeoJSON file
-
Mapping files:
- JSON files in
maps/zonasxseries/
containing manual mappings of series to zones for each department
- JSON files in
Currently supported departments:
- Montevideo
- Maldonado
- Colonia
- Treinta y Tres
The data processing involves several steps:
- Prepare GeoJSON files:
- Run
scripts/convert_to_geojson_by_depto.py
to create separate GeoJSON files for each department
- Run
- Add zone information to GeoJSON:
- Run
notebooks/mapas/add_zones_to_geojson.ipynb
to incorporate zone information into the GeoJSON files
- Run
- Process ODD and ODN data:
- Use the respective notebooks to clean and transform the data
For both ODD and ODN data in each department, the following steps are performed:
- Read Excel files from the specified folders
- Combine data from all files into a single DataFrame
- Filter data for the specific department
- Clean and transform the data:
- Rename columns
- Modify party names
- Remove unnecessary columns
- Add zone information based on the series codes
- Save the processed data to CSV files at various stages
The project generates the following output files for each department:
data/processed/ODD/[department]/[department]_odd_filtered.csv
: Initial filtered ODD datadata/processed/ODD/[department]/[department]_odd_cleaned.csv
: Cleaned ODD datadata/final/odd/[department]/[department]_odd_final.csv
: Final ODD data with zone informationdata/processed/ODN/[department]/[department]_odn_filtered.csv
: Initial filtered ODN datadata/processed/ODN/[department]/[department]_odn_cleaned.csv
: Cleaned ODN datadata/final/odn/[department]/[department]_odn_final.csv
: Final ODN data with zone informationmaps/deptosconzona/[department]_con_zona.geojson
: GeoJSON file with added zone information
- Ensure all required data files are in their respective folders:
- ODD data in
data/raw/results/ODD
- ODN data in
data/raw/results/ODN
- Mapping files in
maps/zonasxseries
- Original shapefile in the project root directory
- ODD data in
- Install the required dependencies (see Dependencies section)
- Run the GeoJSON preparation scripts:
python scripts/convert_to_geojson_by_depto.py
- Open the Jupyter notebooks in your preferred environment:
notebooks/ODD/data_processing_notebook_ODD.ipynb
for ODD datanotebooks/ODN/data_processing_notebook_ODN.ipynb
for ODN datanotebooks/mapas/add_zones_to_geojson.ipynb
for adding zones to GeoJSON files
- Update the
department
variable in the notebooks to process data for different departments - Run all cells in each notebook to process the data
- Check the output files in the respective folders for the results
To add a new department:
- Ensure you have the necessary Excel files for the new department in the ODD and ODN data folders
- Create a new JSON mapping file in
maps/zonasxseries
if the department requires zone mapping - Update the
department
variable in the notebooks to include the new department name - Run the notebooks with the new department to generate the processed data
- Update this README to include the new department in the "Currently supported departments" list
The project includes steps to process GeoJSON files and add zone information:
-
Initial GeoJSON creation:
- The script
scripts/convert_to_geojson_by_depto.py
converts the original shapefile into separate GeoJSON files for each department, stored inmaps/deptos/
.
- The script
-
Adding zones to GeoJSON:
- The notebook
notebooks/mapas/add_zones_to_geojson.ipynb
reads the GeoJSON files created in step 1. - It uses the manually created mappings in
maps/zonasxseries/
to add zone information to each feature in the GeoJSON. - The resulting GeoJSON files with zone information are saved in
maps/deptosconzona/
.
- The notebook
This process enriches the geographical data with zone information, which is crucial for further analysis and visualization.
This project requires the following Python libraries:
- pandas
- numpy
- geopandas
- os
- json
Ensure these libraries are installed in your Python environment before running the scripts and notebooks.
Both the data for the results of the ODD and ODN elections and the shapefile for the geographic data was provided by the Corte Electoral de la Republica Oriental del Uruguay.