Skip to content

Commit 960f038

Browse files
committed
fix NaN values in JSON
1 parent c02689f commit 960f038

File tree

2 files changed

+57
-39
lines changed

2 files changed

+57
-39
lines changed

markdown/2024_insights/03_analysis.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,6 @@ This section highlights vulnerabilities with high impact or severity to assist i
475475
2. **Most Impactful Vulnerabilities**: Combines multiple factors (CVSS, KEV inclusion, exploitation evidence) to rank vulnerabilities.
476476

477477
```python
478-
import pandas as pd
479-
import json
480-
481-
# Set the generated date for metadata
482-
generated_date = "2024-12-30"
483-
484478
# Filter for all CVEs with CVSS_Base_Score of 10.0
485479
cvss_10_cves = df_2024[df_2024['CVSS_Base_Score'] == 10.0].copy()
486480

@@ -551,10 +545,25 @@ specific_cve_details = {
551545
}
552546
}
553547

548+
549+
# Handle NaN values in the output
550+
def handle_nan_values(obj):
551+
if isinstance(obj, float) and pd.isna(obj):
552+
return None # Replace NaN with null for JSON compatibility
553+
if isinstance(obj, dict):
554+
return {key: handle_nan_values(value) for key, value in obj.items()}
555+
if isinstance(obj, list):
556+
return [handle_nan_values(value) for value in obj]
557+
return obj
558+
559+
560+
# Process the JSON data to handle NaN values
561+
specific_cve_details_cleaned = handle_nan_values(specific_cve_details)
562+
554563
# Save the specific CVE details to a JSON file
555564
output_path = "../../data/2024_insights/output/cve_details.json"
556565
with open(output_path, "w") as f:
557-
json.dump(specific_cve_details, f)
566+
json.dump(specific_cve_details_cleaned, f)
558567
```
559568

560569
## CVE Assigner Analysis

notebooks/2024_insights/03_analysis.ipynb

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"metadata": {
77
"collapsed": true,
88
"ExecuteTime": {
9-
"end_time": "2025-01-04T11:09:06.167189Z",
10-
"start_time": "2025-01-04T11:09:06.161084Z"
9+
"end_time": "2025-01-04T11:32:31.707960Z",
10+
"start_time": "2025-01-04T11:32:31.700865Z"
1111
}
1212
},
1313
"source": [
@@ -31,13 +31,13 @@
3131
]
3232
}
3333
],
34-
"execution_count": 48
34+
"execution_count": 64
3535
},
3636
{
3737
"metadata": {
3838
"ExecuteTime": {
39-
"end_time": "2025-01-04T11:09:08.134841Z",
40-
"start_time": "2025-01-04T11:09:06.240914Z"
39+
"end_time": "2025-01-04T11:32:33.188225Z",
40+
"start_time": "2025-01-04T11:32:31.726057Z"
4141
}
4242
},
4343
"cell_type": "code",
@@ -265,12 +265,12 @@
265265
"</div>"
266266
]
267267
},
268-
"execution_count": 49,
268+
"execution_count": 65,
269269
"metadata": {},
270270
"output_type": "execute_result"
271271
}
272272
],
273-
"execution_count": 49
273+
"execution_count": 65
274274
},
275275
{
276276
"metadata": {},
@@ -290,8 +290,8 @@
290290
{
291291
"metadata": {
292292
"ExecuteTime": {
293-
"end_time": "2025-01-04T11:09:08.315714Z",
294-
"start_time": "2025-01-04T11:09:08.288787Z"
293+
"end_time": "2025-01-04T11:32:33.499933Z",
294+
"start_time": "2025-01-04T11:32:33.465548Z"
295295
}
296296
},
297297
"cell_type": "code",
@@ -361,7 +361,7 @@
361361
],
362362
"id": "78362296379ded2c",
363363
"outputs": [],
364-
"execution_count": 50
364+
"execution_count": 66
365365
},
366366
{
367367
"metadata": {},
@@ -380,8 +380,8 @@
380380
{
381381
"metadata": {
382382
"ExecuteTime": {
383-
"end_time": "2025-01-04T11:09:08.445448Z",
384-
"start_time": "2025-01-04T11:09:08.395098Z"
383+
"end_time": "2025-01-04T11:32:33.615619Z",
384+
"start_time": "2025-01-04T11:32:33.571449Z"
385385
}
386386
},
387387
"cell_type": "code",
@@ -459,7 +459,7 @@
459459
],
460460
"id": "127acc20aa0961e5",
461461
"outputs": [],
462-
"execution_count": 51
462+
"execution_count": 67
463463
},
464464
{
465465
"metadata": {},
@@ -479,8 +479,8 @@
479479
{
480480
"metadata": {
481481
"ExecuteTime": {
482-
"end_time": "2025-01-04T11:09:10.757764Z",
483-
"start_time": "2025-01-04T11:09:09.191392Z"
482+
"end_time": "2025-01-04T11:32:34.301903Z",
483+
"start_time": "2025-01-04T11:32:33.686554Z"
484484
}
485485
},
486486
"cell_type": "code",
@@ -632,7 +632,7 @@
632632
],
633633
"id": "82d6e7106cd5a47f",
634634
"outputs": [],
635-
"execution_count": 52
635+
"execution_count": 68
636636
},
637637
{
638638
"metadata": {},
@@ -652,8 +652,8 @@
652652
{
653653
"metadata": {
654654
"ExecuteTime": {
655-
"end_time": "2025-01-04T11:09:10.961030Z",
656-
"start_time": "2025-01-04T11:09:10.781992Z"
655+
"end_time": "2025-01-04T11:32:34.544009Z",
656+
"start_time": "2025-01-04T11:32:34.412398Z"
657657
}
658658
},
659659
"cell_type": "code",
@@ -769,7 +769,7 @@
769769
],
770770
"id": "11754c648da36dec",
771771
"outputs": [],
772-
"execution_count": 53
772+
"execution_count": 69
773773
},
774774
{
775775
"metadata": {},
@@ -787,18 +787,12 @@
787787
{
788788
"metadata": {
789789
"ExecuteTime": {
790-
"end_time": "2025-01-04T11:09:12.736814Z",
791-
"start_time": "2025-01-04T11:09:11.088436Z"
790+
"end_time": "2025-01-04T11:32:36.739691Z",
791+
"start_time": "2025-01-04T11:32:34.727792Z"
792792
}
793793
},
794794
"cell_type": "code",
795795
"source": [
796-
"import pandas as pd\n",
797-
"import json\n",
798-
"\n",
799-
"# Set the generated date for metadata\n",
800-
"generated_date = \"2024-12-30\"\n",
801-
"\n",
802796
"# Filter for all CVEs with CVSS_Base_Score of 10.0\n",
803797
"cvss_10_cves = df_2024[df_2024['CVSS_Base_Score'] == 10.0].copy()\n",
804798
"\n",
@@ -869,14 +863,29 @@
869863
" }\n",
870864
"}\n",
871865
"\n",
866+
"\n",
867+
"# Handle NaN values in the output\n",
868+
"def handle_nan_values(obj):\n",
869+
" if isinstance(obj, float) and pd.isna(obj):\n",
870+
" return None # Replace NaN with null for JSON compatibility\n",
871+
" if isinstance(obj, dict):\n",
872+
" return {key: handle_nan_values(value) for key, value in obj.items()}\n",
873+
" if isinstance(obj, list):\n",
874+
" return [handle_nan_values(value) for value in obj]\n",
875+
" return obj\n",
876+
"\n",
877+
"\n",
878+
"# Process the JSON data to handle NaN values\n",
879+
"specific_cve_details_cleaned = handle_nan_values(specific_cve_details)\n",
880+
"\n",
872881
"# Save the specific CVE details to a JSON file\n",
873882
"output_path = \"../../data/2024_insights/output/cve_details.json\"\n",
874883
"with open(output_path, \"w\") as f:\n",
875-
" json.dump(specific_cve_details, f)"
884+
" json.dump(specific_cve_details_cleaned, f)"
876885
],
877886
"id": "387ed0168ac5725a",
878887
"outputs": [],
879-
"execution_count": 54
888+
"execution_count": 70
880889
},
881890
{
882891
"metadata": {},
@@ -894,8 +903,8 @@
894903
{
895904
"metadata": {
896905
"ExecuteTime": {
897-
"end_time": "2025-01-04T11:09:13.344786Z",
898-
"start_time": "2025-01-04T11:09:12.829511Z"
906+
"end_time": "2025-01-04T11:32:37.432858Z",
907+
"start_time": "2025-01-04T11:32:36.832421Z"
899908
}
900909
},
901910
"cell_type": "code",
@@ -980,7 +989,7 @@
980989
],
981990
"id": "ffd736d262cf033f",
982991
"outputs": [],
983-
"execution_count": 55
992+
"execution_count": 71
984993
}
985994
],
986995
"metadata": {

0 commit comments

Comments
 (0)