# Export Statistics to CSV

**URL:** <https://discourse.slicer.org/t/export-statistics-to-csv/15926>\
**Category:** Support\
**Tags:** python\
**Created:** [February 9, 2021, 9:47pm UTC](https://discourse.slicer.org/t/export-statistics-to-csv/15926 "2021-02-09T21:47:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pete](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@Pete](https://discourse.slicer.org/u/Pete)\
**Post date:** [February 9, 2021, 9:47pm UTC](https://discourse.slicer.org/t/export-statistics-to-csv/15926/1 "2021-02-09T21:47:28Z")

</div>

Hi,

I am trying to export the calculated statistics/table from the following code to CSV, but obviously the exportToCSVFile isn’t working properly. I don’t know what to replace self with or how to structure this function. Any help greatly appreciated!

```
## Set masterVolumeNode to first volume node, similar to export Script
masterVolumeNode = slicer.mrmlScene.GetFirstNodeByClass('vtkMRMLScalarVolumeNode')

segmentationNode = getNode('Segmentation')

# Compute segment volumes
resultsTableNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLTableNode')
import SegmentStatistics
segStatLogic = SegmentStatistics.SegmentStatisticsLogic()
segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID())
segStatLogic.getParameterNode().SetParameter("ScalarVolume", masterVolumeNode.GetID())
segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.enabled","False")
segStatLogic.getParameterNode().SetParameter("ScalarVolumeSegmentStatisticsPlugin.voxel_count.enabled","False")
segStatLogic.getParameterNode().SetParameter("ScalarVolumeSegmentStatisticsPlugin.volume_mm3.enabled","False")
segStatLogic.computeStatistics()
segStatLogic.exportToTable(resultsTableNode)
segStatLogic.showTable(resultsTableNode)

testCSV = "/Users/pete/Desktop/test.csv"

segStatLogic.exportToCSVFile(self, testCSV)
```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 10, 2021, 2:33am UTC](https://discourse.slicer.org/t/export-statistics-to-csv/15926/2 "2021-02-10T02:33:32Z")

</div>

Everything is correct except the last line. The correct syntax is:

```
segStatLogic.exportToCSVFile(testCSV)
```

---

<div class="post-metadata">

**Author:** ![Pete](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@Pete](https://discourse.slicer.org/u/Pete)\
**Post date:** [February 11, 2021, 9:54pm UTC](https://discourse.slicer.org/t/export-statistics-to-csv/15926/3 "2021-02-11T21:54:02Z")

</div>

So obvious, thank you again!
