Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: object of type 'method' has no len() [closed]

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))

Hey Guys. Im trying to write a script that would calculate endpoints for a medical task. When I run the program, it works all the way until it hits the first for loop of the script. I'm pretty sure there is an error because CategoryID doesnt have a length property. But I also think it should because I'm converting it to a list in the beginning. Any suggestions on how to fix this? Thanks in advance.

like image 411
Ryan Chen Avatar asked Nov 07 '16 15:11

Ryan Chen


1 Answers

It seems like you forgot the () after tolist method, so it can be parsed as a call to the method, and not the method itself:

CategoryID = dataframe['CategoryID'].tolist()
ReactionTime = dataframe['ReactionTime'].tolist()
CorrectResponse = dataframe['CorrectResponse'].tolist()
like image 182
Christian Tapia Avatar answered Oct 24 '22 09:10

Christian Tapia