Datasets:

Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
Libraries:
Datasets
License:
File size: 3,866 Bytes
f827258
1
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyNO+e07xDwTXLgso0Smk0vJ"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","source":["import json\n","import os\n","\n","import datasets\n","\n","_DESCRIPTION = \"\"\"\n","The datasets were collected and published to present the educational level of NC population in different areas. The educational attainment for the black population data can raise concern for the educational equity issue in North Carolina. The combined dataset aims to offer a holistic perspective on educational levels and equity, with a specific focus on the educational attainment of the Black population aged 25 and over.\n","\"\"\"\n","\n","_HOMEPAGE = \"https://huggingface.co/datasets/YXu120/NC_Education\"\n","\n","_LICENSE = \"cc-by-sa-4.0\"\n","\n","_URL = \"/content/drive/MyDrive/Colab_Notebooks/NC_Education/NC_Education_Final.csv\"\n","\n","class NCEducationDataset(datasets.GeneratorBasedBuilder):\n","    VERSION = datasets.Version(\"1.0.0\")\n","\n","    def _info(self):\n","        features = datasets.Features(\n","            {\n","                \"area_name\": datasets.Value(\"string\"),\n","                \"area_type\": datasets.Value(\"string\"),\n","                \"years\": datasets.Sequence(\n","                    {\n","                        \"year\": datasets.Value(\"string\"),\n","                        \"variables\": datasets.Sequence(\n","                            {\n","                                \"variable\": datasets.Value(\"string\"),\n","                                \"value\": datasets.Value(\"int32\"),\n","                                \"value_black\": datasets.Value(\"int32\"),\n","                            }\n","                        ),\n","                    }\n","                ),\n","            }\n","        )\n","\n","        return datasets.DatasetInfo(\n","            description=_DESCRIPTION,\n","            features=features,\n","            homepage=_HOMEPAGE,\n","            license=_LICENSE,\n","        )\n","\n","    def _split_generators(self, dl_manager):\n","        data_file = dl_manager.download(_URL)\n","        return [\n","            datasets.SplitGenerator(\n","                name=datasets.Split.TRAIN,\n","                gen_kwargs={\n","                    \"filepath\": data_file,\n","                },\n","            )\n","        ]\n","\n","    def _generate_examples(self, filepath):\n","        with open(filepath, \"r\", encoding=\"utf-8\") as file:\n","            data = json.load(file)\n","            for idx, (area_name, area_data) in enumerate(data.items()):\n","                years_data = []\n","                for year, variables in area_data[\"years\"].items():\n","                    year_data = {\n","                        \"year\": year,\n","                        \"variables\": [\n","                            {\n","                                \"variable\": variable[\"variable\"],\n","                                \"value\": variable[\"value\"],\n","                                \"value_black\": variable.get(\"value_black\"),\n","                            }\n","                            for variable in variables\n","                        ],\n","                    }\n","                    years_data.append(year_data)\n","\n","                yield idx, {\n","                    \"area_name\": area_name,\n","                    \"area_type\": area_data[\"area_type\"],\n","                    \"years\": years_data,\n","                }"],"metadata":{"id":"EydAuFx4AKlR","executionInfo":{"status":"ok","timestamp":1710722455431,"user_tz":240,"elapsed":124,"user":{"displayName":"Yangxuan Xu","userId":"16693520489565507742"}}},"execution_count":9,"outputs":[]}]}