Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Download batch_scripts/caps_directory_reader.py from Climate-Lab/climate-policy-tracker: direct link, hf CLI and curl.
- Browser
- Download file 754 Bytes
-
https://huggingface.co/spaces/Climate-Lab/climate-policy-tracker/resolve/cedddaeeffb97c2ff2efc2f9c479335afd44e25e/batch_scripts/caps_directory_reader.py
- Command line
-
hf download hf://spaces/Climate-Lab/climate-policy-tracker@cedddaeeffb97c2ff2efc2f9c479335afd44e25e/batch_scripts/caps_directory_reader.py
-
curl -L -o caps_directory_reader.py https://huggingface.co/spaces/Climate-Lab/climate-policy-tracker/resolve/cedddaeeffb97c2ff2efc2f9c479335afd44e25e/batch_scripts/caps_directory_reader.py
754 Bytes
| import os | |
| import pandas as pd | |
| import re | |
| # Define the folder path containing the files | |
| caps_folder = "./CAPS" | |
| # List all files in the CAPS folder | |
| files = os.listdir(caps_folder) | |
| # Define a regex pattern to extract city, state, year, and plan type | |
| pattern = re.compile(r"^(.*?),\s([A-Z]{2})\s(.{3,}?)\s(\d{4})\.pdf$") | |
| # Extract information from file names | |
| data = [] | |
| for file in files: | |
| match = pattern.match(file) | |
| if match: | |
| city, state, plan_type, year = match.groups() | |
| data.append([city.strip(), state, year, plan_type.strip()]) | |
| # Convert to DataFrame | |
| df = pd.DataFrame(data, columns=["City", "State", "Year", "Plan Type"]) | |
| # Save to CSV | |
| df.to_csv("./caps_plans.csv", index=False) | |
| print(f"CSV file saved to: caps_plans.csv") | |