Datasets:

Languages:
English
Size Categories:
1K<n<10K
Tags:
License:
YXu120 commited on
Commit
5543393
1 Parent(s): 2b7b5c8
Dataset loading script.ipynb → Dataset loading script.py RENAMED
File without changes
dataset_loading_script.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Dataset loading script.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1ceCOKzOpSOMsgkw__rxtBVv7R3QrSkbg
8
+ """
9
+
10
+ import csv
11
+ import os
12
+
13
+ import datasets
14
+
15
+ _DESCRIPTION = """
16
+ 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.
17
+ """
18
+
19
+ _HOMEPAGE = "https://huggingface.co/datasets/YXu120/NC_Education"
20
+
21
+ _LICENSE = "cc-by-sa-4.0"
22
+
23
+ _URL = "https://drive.google.com/uc?id=1Au9xwsnDkRx4TMWwndWKbzLR5u9WXUQZ"
24
+
25
+ class NCEducationDataset(datasets.GeneratorBasedBuilder):
26
+
27
+ VERSION = datasets.Version("1.0.1")
28
+
29
+ def _info(self):
30
+ features = datasets.Features(
31
+ {
32
+ "area_name": datasets.Value("string"),
33
+ "area_type": datasets.Value("string"),
34
+ "years": datasets.Sequence(
35
+ {
36
+ "year": datasets.Value("int64"),
37
+ "variables": datasets.Sequence(
38
+ {
39
+ "variable": datasets.Value("string"),
40
+ "value": datasets.Value("int64"),
41
+ "value_black": datasets.Value("int64")
42
+ }
43
+ )
44
+ }
45
+ )
46
+ }
47
+ )
48
+
49
+ return datasets.DatasetInfo(
50
+ description = _DESCRIPTION,
51
+ features = features,
52
+ homepage = _HOMEPAGE,
53
+ license = _LICENSE,
54
+ )
55
+
56
+ def _split_generators(self, dl_manager):
57
+ data_file = dl_manager.download(_URL)
58
+ return [
59
+ datasets.SplitGenerator(
60
+ name = "train",
61
+ gen_kwargs = {
62
+ "filepath": data_file,
63
+ },
64
+ )
65
+ ]
66
+
67
+ def _generate_examples(self, filepath):
68
+ data = {}
69
+ with open(filepath, "r", encoding="utf-8") as file:
70
+ csv_reader = csv.DictReader(file)
71
+ for row in csv_reader:
72
+ area_name = row["area_name"]
73
+ area_type = row["area_type"]
74
+ year = int(row["year"])
75
+ variable = row["variable"]
76
+ value = int(row["value"]) if row["value"] else None
77
+ value_black = int(row["value_black"]) if row["value_black"] else None
78
+
79
+ if area_name not in data:
80
+ data[area_name] = {
81
+ "area_type": area_type,
82
+ "years": {}
83
+ }
84
+
85
+ if year not in data[area_name]["years"]:
86
+ data[area_name]["years"][year] = []
87
+
88
+ data[area_name]["years"][year].append({
89
+ "variable": variable,
90
+ "value": value,
91
+ "value_black": value_black
92
+ })
93
+
94
+ for idx, (area_name, area_data) in enumerate(data.items()):
95
+ years_data = []
96
+ for year, variables in area_data["years"].items():
97
+ year_data = {
98
+ "year": year,
99
+ "variables": variables
100
+ }
101
+ years_data.append(year_data)
102
+
103
+ yield idx, {
104
+ "area_name": area_name,
105
+ "area_type": area_data["area_type"],
106
+ "years": years_data
107
+ }