MurathanKurfali commited on
Commit
43a1d8a
·
1 Parent(s): b226b85

topic update

Browse files
cdp/topic/cities/test.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:99beaeddb4838a3f6b7ec2cdc25e344a5ec774f730eb823dff93ba4418cdfff3
3
- size 11398970
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b4b14c1c04104870e44e49566bd24eb63b77cfd7d89b5359163daa124142cbea
3
+ size 4631307
cdp/topic/cities/train.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6150a3badeca7a3d334771a53d79f17f119b9919b341f10ba828c5185d2a5bb7
3
- size 58703179
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d26f3b900dc17b7fd7a56c6e0d0b39821ef64d008478e7c75f8d1aa7dab334f
3
+ size 23729214
cdp/topic/cities/val.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f9dac25c472aefb571b2df1689728ccdbcf8b7bf902e13fc406c28f44b04460f
3
- size 10193947
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f4442ccf3d24865be4eaaf8d5139a3230d75b7b7f893363a8b17a133dee2498a
3
+ size 4067182
cdp/topic/prepare_cdp_topic.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pandas as pd
3
+ import datasets
4
+
5
+ # Define labels and columns to drop
6
+ labels = ["Adaptation", "Buildings", "Climate Hazards", "Emissions", "Energy", "Food",
7
+ "Governance and Data Management", "Opportunities", "Strategy", "Transport",
8
+ "Waste", "Water"]
9
+
10
+ columns_to_drop = ["id", "Year Reported to CDP", "Organization", "Parent Section",
11
+ "Section", "Question Name", "Row Name", "Comments", "Response Answer"]
12
+
13
+ # Define dataset split paths
14
+ split_paths = {
15
+ "train": "https://huggingface.co/datasets/iceberg-nlp/climabench/resolve/main/all_data/CDP/Cities/Cities%20Responses/train.csv",
16
+ "val": "https://huggingface.co/datasets/iceberg-nlp/climabench/resolve/main/all_data/CDP/Cities/Cities%20Responses/val.csv",
17
+ "test": "https://huggingface.co/datasets/iceberg-nlp/climabench/resolve/main/all_data/CDP/Cities/Cities%20Responses/test.csv"
18
+ }
19
+
20
+ # Define output directory
21
+ output_dir = "cdp_topic/cities"
22
+ os.makedirs(output_dir, exist_ok=True) # Create directory if it doesn't exist
23
+
24
+
25
+ def label_to_id(example):
26
+ """Maps the Category/Label to an index based on the labels list."""
27
+ example["label_index"] = labels.index(example["Label"])
28
+ return example
29
+
30
+
31
+ def prepare_topic_dataset(df: pd.DataFrame) -> pd.DataFrame:
32
+ """Prepares the dataset by removing unwanted columns and adding label indices."""
33
+ df = df.drop(columns=columns_to_drop, errors="ignore") # Remove unnecessary columns
34
+ df["label_index"] = df["Label"].apply(lambda x: labels.index(x))
35
+ return df
36
+
37
+
38
+ # Process and save each split
39
+ for split, url in split_paths.items():
40
+ print(f"Processing {split} split...")
41
+
42
+ # Load dataset
43
+ df = pd.read_csv(url) # Read CSV directly from URL
44
+
45
+ # Prepare dataset
46
+ df = prepare_topic_dataset(df)
47
+
48
+ # Save to local CSV
49
+ save_path = os.path.join(output_dir, f"{split}.csv")
50
+ df.to_csv(save_path, index=False)
51
+
52
+ print(f"Saved: {save_path}")
53
+
54
+ print("All datasets processed and saved successfully!")