I am not able to write the details extracted from a DICOM file to a CSV file. Here's the code which I have used -
import pydicom
import os
import pandas as pd
import csv
import glob
data_dir= 'C:\\Users\\dmgop\\Personal\\TE Project - Pneumonia\\stage_1_test_images_dicom'
patients= os.listdir(data_dir)
myFile= open('patientdata.csv','w')
for image in patients:
lung = pydicom.dcmread(os.path.join(data_dir, image))
print (lung)
writer = csv.writer(myFile)
writer.writerows(lung)
break
The error which is coming up is as follows -
Traceback (most recent call last): File "C:\Users\dmgop\AppData\Local\Programs\Python\Python36\lib\site-packages\pydicom-1.2.0rc1-py3.6.egg\pydicom\dataelem.py",
line 344, in getitem
return self.value[key] TypeError: 'PersonName3' object does not support
indexingDuring handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\dmgop\Personal\TE
Project - Pneumonia\detail_extraction.py", line 14, in
writer.writerows(lung) File
"C:\Users\dmgop\AppData\Local\Programs\Python\Python36\lib\site-packages\pydicom-1.2.0rc1-py3.6.egg\pydicom\dataelem.py",
line 346, in getitem
raise TypeError("DataElement value is unscriptable " TypeError: DataElement value is unscriptable (not a Sequence)