Mr.X
Mr.X

Reputation: 11

How to fix TypeError: unsupported operand type(s)?

This is my code to read .csv files. I want to devide the data to training set and testing set and label them. `

train_df = file_full[:len(file_full)//2]

labels=[ 0 for i in range(len(file_full))//2]

train_df=train_df.appen(file_bottom[:len(file_bottom)//2])

for i in range(len(file_bottom)//2):

    labels.append(1)

    train_df['label']=labels

    train = train_df.drop('label',axis=1)

    train_label= train_df['label']`

However, I am getting this error.

labels=[ 0 for i in range(len(file_full))//2]

TypeError: unsupported operand type(s) for //: 'range' and 'int'

I thought is providing a number and I am taking half of it. what is the problem?

Upvotes: 0

Views: 664

Answers (1)

paupaulaz
paupaulaz

Reputation: 977

Your parenthesis are wrong. You are trying to divide a range object by two, which doesn't make sense. Try this:

labels=[ 0 for i in range(len(file_full)//2)]

Upvotes: 2

Related Questions