<p>我做了以下几件事,它奏效了:1。将if-if-elif结构替换为if-elif-else(见下文)。2将dec计算为字符串(即dec=='1'而不是dec==1)</p>
<pre><code>if len(SframeDup.index) > 0 and dec == '1':
SframeDup.to_csv('NWEA CSVs/Students/StudentDuplicates.csv', sep=',')
print ("%d instances of repeated student IDs detected." % len(SframeDup.index))
print ("See StudentDuplicates.csv for duplicates.")
print ("\nThis program will now stop.")
raise SystemExit
#quit() and exit() work too, but only in the editor
#doing this in Ipython Notebook will restart the kernal and require
#re-running and re-compiling preceeding code
elif len(SframeDup.index) >0 and dec == '2':
print ("%d instances of repeated student IDs detected." % len(SframeDup.index))
print ("See StudentDuplicates.csv for duplicates.")
Sframe['dup_check_1'] = Sframe.duplicated(cols = ['TermName', 'SchoolName', 'StudentID'], take_last = False)
Sframe['dup_check_2'] = Sframe.duplicated(cols = ['TermName', 'SchoolName', 'StudentID'], take_last = True)
Sframe = Sframe[(Sframe['dup_check_1'] == False) & (Sframe['dup_check_2'] == False)]
del Sframe['dup_check_1'], Sframe['dup_check_2']
else:
print ("No duplicates found. Oh yeah!")
</code></pre>