다음 루프가 있습니다.
lines = []
for dicom in mydicoms:
dcm1 = pydicom.dcmread(dicom)
identity = dcm1.PatientID
age = dcm1.PatientAge
sex = dcm1.PatientSex
modality = dcm1.Modality
finding = dcm1.StudyDescription
rows = dcm1.Rows
columns = dcm1.Columns
new_row = {'id':identity, 'age':age, 'sex':sex, 'modality':modality, 'finding':finding, 'rows':rows, 'columns':columns}
df.append(new_row, ignore_index = True)
lines.append(new_row)
나중에 df를 확인하면 비어 있습니다.
루프에서 코드의 일부를 복사하여 붙여 넣거나 다른 Jupyter 셀에서 다음 중 하나를 수행 할 때 :
df.append(new_row, ignore_index=True)
df.append(lines, ignore_index = True)
루프 내부가 아니라 올바르게 추가합니다.
내가 무엇을 놓치고 있습니까?
anky 에서 언급했듯이 df
변수에 다시 할당해야합니다 .
수정 된 코드는 다음과 같습니다.
lines = []
for dicom in mydicoms:
dcm1 = pydicom.dcmread(dicom)
identity = dcm1.PatientID
age = dcm1.PatientAge
sex = dcm1.PatientSex
modality = dcm1.Modality
finding = dcm1.StudyDescription
rows = dcm1.Rows
columns = dcm1.Columns
new_row = {'id':identity, 'age':age, 'sex':sex, 'modality':modality, 'finding':finding, 'rows':rows, 'columns':columns}
df = df.append(new_row, ignore_index = True)
lines.append(new_row)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다