Skip to content

Commit 0d52a53

Browse files
committed
add pandas support
1 parent c3752ba commit 0d52a53

File tree

4 files changed

+459
-472
lines changed

4 files changed

+459
-472
lines changed

examples/examples_2023_release/ang_frame_conversion_and_json.ipynb

Lines changed: 144 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,18 @@
401401
"entry.measurements[0].x_units = \"CM-degrees\""
402402
]
403403
},
404+
{
405+
"cell_type": "markdown",
406+
"id": "dce1090e-0ec3-4a98-90af-d64d7b422f56",
407+
"metadata": {},
408+
"source": [
409+
"### Converting distributions to Pandas DataFrames"
410+
]
411+
},
404412
{
405413
"cell_type": "code",
406414
"execution_count": 14,
407-
"id": "e8c85184-1197-4132-9a27-c3cca8149ffc",
415+
"id": "7e1539b6-f20d-4931-907d-183715f3dbcb",
408416
"metadata": {},
409417
"outputs": [
410418
{
@@ -425,107 +433,152 @@
425433
{
426434
"cell_type": "code",
427435
"execution_count": 15,
428-
"id": "9b51ea7f-0237-47d6-8b94-110b5140bf2c",
436+
"id": "21ec357f-4b19-40ea-92c2-7f592da636f3",
437+
"metadata": {},
438+
"outputs": [
439+
{
440+
"data": {
441+
"text/html": [
442+
"<div>\n",
443+
"<style scoped>\n",
444+
" .dataframe tbody tr th:only-of-type {\n",
445+
" vertical-align: middle;\n",
446+
" }\n",
447+
"\n",
448+
" .dataframe tbody tr th {\n",
449+
" vertical-align: top;\n",
450+
" }\n",
451+
"\n",
452+
" .dataframe thead th {\n",
453+
" text-align: right;\n",
454+
" }\n",
455+
"</style>\n",
456+
"<table border=\"1\" class=\"dataframe\">\n",
457+
" <thead>\n",
458+
" <tr style=\"text-align: right;\">\n",
459+
" <th></th>\n",
460+
" <th>type</th>\n",
461+
" <th>energy</th>\n",
462+
" <th>energy_err</th>\n",
463+
" <th>energy_units</th>\n",
464+
" <th>EXFORAccessionNumber</th>\n",
465+
" <th>source</th>\n",
466+
" <th>x_units</th>\n",
467+
" <th>y_units</th>\n",
468+
" <th>data</th>\n",
469+
" </tr>\n",
470+
" </thead>\n",
471+
" <tbody>\n",
472+
" <tr>\n",
473+
" <th>0</th>\n",
474+
" <td>ECS</td>\n",
475+
" <td>0.7</td>\n",
476+
" <td>0.004</td>\n",
477+
" <td>MeV</td>\n",
478+
" <td>21782032</td>\n",
479+
" <td>G.Haouat, J.Lachkar, et al., Nuclear Science a...</td>\n",
480+
" <td>CM-degrees</td>\n",
481+
" <td>barns/ster</td>\n",
482+
" <td>{'x': [70.45755591846655, 85.48097468773834, 9...</td>\n",
483+
" </tr>\n",
484+
" </tbody>\n",
485+
"</table>\n",
486+
"</div>"
487+
],
488+
"text/plain": [
489+
" type energy energy_err energy_units EXFORAccessionNumber \\\n",
490+
"0 ECS 0.7 0.004 MeV 21782032 \n",
491+
"\n",
492+
" source x_units y_units \\\n",
493+
"0 G.Haouat, J.Lachkar, et al., Nuclear Science a... CM-degrees barns/ster \n",
494+
"\n",
495+
" data \n",
496+
"0 {'x': [70.45755591846655, 85.48097468773834, 9... "
497+
]
498+
},
499+
"execution_count": 15,
500+
"metadata": {},
501+
"output_type": "execute_result"
502+
}
503+
],
504+
"source": [
505+
"entry.measurements[0].to_dataframe(entry.meta.citation())"
506+
]
507+
},
508+
{
509+
"cell_type": "markdown",
510+
"id": "1990fbdd-704e-4224-8e19-b6fb49e1995a",
511+
"metadata": {},
512+
"source": [
513+
"### Writing to JSON"
514+
]
515+
},
516+
{
517+
"cell_type": "code",
518+
"execution_count": 16,
519+
"id": "1cb08f79-99b6-43b9-a2e8-84d2a2a9c39f",
429520
"metadata": {},
430521
"outputs": [
431522
{
432523
"name": "stdout",
433524
"output_type": "stream",
434525
"text": [
435-
"{\n",
436-
" \"type\": \"ECS\",\n",
437-
" \"energy\": 0.7,\n",
438-
" \"energy-err\": 0.004,\n",
439-
" \"ex-energy\": 0.0,\n",
440-
" \"ex-energy-err\": 0.0,\n",
441-
" \"ex-energy-units\": null,\n",
442-
" \"energy-units\": \"MeV\",\n",
443-
" \"EXFORAccessionNumber\": \"21782032\",\n",
444-
" \"source\": \"G.Haouat, J.Lachkar, et al., Nuclear Science and Engineering 81, (4), 491 (1982); Report other than progress report: NEANDC-158 27 (1982); Report other than progress report: CEA-N-2197 (1981); Report other than progress report: INDC(FR)-0044 (1981); Conf.on Nucl.Cross Sections F.Techn.,Knoxville 1979 672 (1979); Private communication: Haouat (1981); Data taken from the EXFOR database, file EXFOR 21782001 dated 1982, retrieved from the IAEA Nuclear Data Services website.\",\n",
445-
" \"data\": {\n",
446-
" \"angle\": [\n",
447-
" 70.45755591846655,\n",
448-
" 85.48097468773834,\n",
449-
" 90.48180656106129,\n",
450-
" 95.48079812958292,\n",
451-
" 105.43334931945421,\n",
452-
" 115.41879491965597,\n",
453-
" 125.39759253633743,\n",
454-
" 135.3703864152539,\n",
455-
" 145.23834956357058,\n",
456-
" 155.20180986664212\n",
457-
" ],\n",
458-
" \"angle-units\": \"CM-degrees\",\n",
459-
" \"angle-err\": [\n",
460-
" 0.0,\n",
461-
" 0.0,\n",
462-
" 0.0,\n",
463-
" 0.0,\n",
464-
" 0.0,\n",
465-
" 0.0,\n",
466-
" 0.0,\n",
467-
" 0.0,\n",
468-
" 0.0,\n",
469-
" 0.0\n",
470-
" ],\n",
471-
" \"cs\": [\n",
472-
" 0.242,\n",
473-
" 0.2087,\n",
474-
" 0.2105,\n",
475-
" 0.22290000000000001,\n",
476-
" 0.18869999999999998,\n",
477-
" 0.1889,\n",
478-
" 0.13740000000000002,\n",
479-
" 0.13740000000000002,\n",
480-
" 0.09097,\n",
481-
" 0.09532\n",
482-
" ],\n",
483-
" \"cs-units\": \"barns/ster\",\n",
484-
" \"cs-err\": [\n",
485-
" 0.0242,\n",
486-
" 0.029217999999999997,\n",
487-
" 0.023155000000000002,\n",
488-
" 0.028977000000000003,\n",
489-
" 0.027361499999999997,\n",
490-
" 0.026446,\n",
491-
" 0.020610000000000003,\n",
492-
" 0.020610000000000003,\n",
493-
" 0.014555199999999999,\n",
494-
" 0.0152512\n",
495-
" ],\n",
496-
" \"systematic_normalization_error\": [\n",
497-
" 0.0,\n",
498-
" 0.0,\n",
499-
" 0.0,\n",
500-
" 0.0,\n",
501-
" 0.0,\n",
502-
" 0.0,\n",
503-
" 0.0,\n",
504-
" 0.0,\n",
505-
" 0.0,\n",
506-
" 0.0\n",
507-
" ],\n",
508-
" \"systematic_offset_error\": [\n",
509-
" 0.0,\n",
510-
" 0.0,\n",
511-
" 0.0,\n",
512-
" 0.0,\n",
513-
" 0.0,\n",
514-
" 0.0,\n",
515-
" 0.0,\n",
516-
" 0.0,\n",
517-
" 0.0,\n",
518-
" 0.0\n",
519-
" ]\n",
526+
"[\n",
527+
" {\n",
528+
" \"type\":\"ECS\",\n",
529+
" \"energy\":0.7,\n",
530+
" \"energy_err\":0.004,\n",
531+
" \"energy_units\":\"MeV\",\n",
532+
" \"EXFORAccessionNumber\":\"21782032\",\n",
533+
" \"source\":\"G.Haouat, J.Lachkar, et al., Nuclear Science and Engineering 81, (4), 491 (1982); Report other than progress report: NEANDC-158 27 (1982); Report other than progress report: CEA-N-2197 (1981); Report other than progress report: INDC(FR)-0044 (1981); Conf.on Nucl.Cross Sections F.Techn.,Knoxville 1979 672 (1979); Private communication: Haouat (1981); Data taken from the EXFOR database, file EXFOR 21782001 dated 1982, retrieved from the IAEA Nuclear Data Services website.\",\n",
534+
" \"x_units\":\"CM-degrees\",\n",
535+
" \"y_units\":\"barns\\/ster\",\n",
536+
" \"data\":{\n",
537+
" \"x\":[\n",
538+
" 70.4575559185,\n",
539+
" 85.4809746877,\n",
540+
" 90.4818065611,\n",
541+
" 95.4807981296,\n",
542+
" 105.4333493195,\n",
543+
" 115.4187949197,\n",
544+
" 125.3975925363,\n",
545+
" 135.3703864153,\n",
546+
" 145.2383495636,\n",
547+
" 155.2018098666\n",
548+
" ],\n",
549+
" \"y\":[\n",
550+
" 0.242,\n",
551+
" 0.2087,\n",
552+
" 0.2105,\n",
553+
" 0.2229,\n",
554+
" 0.1887,\n",
555+
" 0.1889,\n",
556+
" 0.1374,\n",
557+
" 0.1374,\n",
558+
" 0.09097,\n",
559+
" 0.09532\n",
560+
" ],\n",
561+
" \"y_err\":[\n",
562+
" 0.0242,\n",
563+
" 0.029218,\n",
564+
" 0.023155,\n",
565+
" 0.028977,\n",
566+
" 0.0273615,\n",
567+
" 0.026446,\n",
568+
" 0.02061,\n",
569+
" 0.02061,\n",
570+
" 0.0145552,\n",
571+
" 0.0152512\n",
572+
" ]\n",
573+
" }\n",
520574
" }\n",
521-
"}\n"
575+
"]\n"
522576
]
523577
}
524578
],
525579
"source": [
526-
"#NBVAL_CHECK_OUTPUT\n",
527-
"\n",
528-
"print(entry.measurements[0].to_json(entry.meta.citation()))"
580+
"df = entry.measurements[0].to_dataframe(entry.meta.citation())\n",
581+
"print(df.to_json(indent=4, orient=\"records\"))"
529582
]
530583
}
531584
],

0 commit comments

Comments
 (0)