2016-11-07 2 views
1
def DS(): 
import os 
import pandas as pd 

directory=input('What folder would you like to work in? (Example: /Users/hem/Desktop/pythontest/ ') 
filename=input('Please enter the name (including .csv) of the file you would like to analyze ') 
idkey=input('What is the subject ID you are analyzing? ' ) 
sessionkey=input('What session of testing are you analyzing? ')  
print('---------- Calculating Drug Stroop endpoints ----------') 
os.chdir(directory) 
dataframe = pd.read_csv(filename, error_bad_lines=False) 
output={} 

CategoryID = dataframe['CategoryID'].tolist 
ReactionTime = dataframe['ReactionTime'].tolist 
CorrectResponse = dataframe['CorrectResponse'].tolist 

#Stroop interference score 
totalN = 0 
countN = 0 
CorrectResponseNeutral = 0 
for i in range(len(CategoryID)): 
    if CategoryID[i] == 1: 
     totalN + ReactionTime[i] 
     countN + 1 
     CorrectResponseNeutral + CorrectResponse[i] 

AverageRTNeutral = totalN/countN 
CorrectResponseNeutral = CorrectResponseNeutral/countN 

totalD = 0 
countD = 0 
CorrectResponseDrug = 0 
for i in range(len(CategoryID)): 
    if CategoryID[i] == 2: 
     totalD + ReactionTime[i] 
     countD + 1 
     CorrectResponseDrug + CorrectResponse[i] 

AverageRTDrug = totalD/countD 
CorrectResponseDrug = CorrectResponseDrug/countD 
InterferenceScore = AverageRTNeutral - AverageRTDrug  


output['SubjectID'] = idkey 
output['Session'] = sessionkey 
output['Interference Score'] = InterferenceScore 
output['Accuracy of Neutral Trials'] = CorrectResponseNeutral 
output['Accuracy of Drug Trials'] = CorrectResponseDrug 
print('---------- Done calculating endpoints ----------') 
outputname=input('What would you like to name your outputfile? (Please include.csv)') 

outputdataframe = pd.DataFrame.from_dict([output]) 
outputdataframe.to_csv(os.path.join('/Users/hem/Desktop/Analysis/DrugStroopAnalyzed',outputname)) 

Hallo Leute. Ich versuche, ein Skript zu schreiben, das Endpunkte für eine medizinische Aufgabe berechnet. Wenn ich das Programm ausführe, funktioniert es solange, bis es die erste for-Schleife des Skripts erreicht. Ich bin ziemlich sicher, dass es einen Fehler gibt, weil CategoryID keine Längeneigenschaft hat. Aber ich denke auch, dass es sollte, weil ich es am Anfang in eine Liste umwandele. Irgendwelche Vorschläge, wie Sie das beheben können? Danke im Voraus.TypeError: Objekt des Typs 'Methode' hat keine len()

+0

können Sie auch die Traceback für den Fehler enthalten bitte? –

+1

Sie ordnen 'CategoryID' einer Methode zu:' CategoryID = Dataframe ['CategoryID']. Tolist'. Sie haben vergessen, 'tolist' zu nennen, d. H.' CategoryID = Dataframe ['CategoryID']. Tolist() '. –

Antwort

1

Es scheint, wie Sie die () nach tolist Methode vergessen haben, so kann es als einen Aufruf der Methode analysiert werden, und nicht die Methode selbst:

CategoryID = dataframe['CategoryID'].tolist() 
ReactionTime = dataframe['ReactionTime'].tolist() 
CorrectResponse = dataframe['CorrectResponse'].tolist() 
+1

Vielen Dank !! Es funktioniert jetzt. –

Verwandte Themen