1

I am trying to read a csv, add columns and then set values for each cell in the new columns. but I can the below error

 raise Exception("cannot handle a non-unique multi-index!")
Exception: cannot handle a non-unique multi-index!

My csv data does not have any index column, I don't know how add an incremental numeric index column to it.

I tried print("data.columns = ", data.columns) but I can see all of the columns are part of the index which is incorrect.

data = pd.read_csv( filename, names=colnames, header=None )
# data = data.drop(['datetime'], axis=1)
data[ "positive" ] = 0
data[ "negative" ] = 0
data[ "hate_speech" ] = 0
data[ "neither" ] = 0
data[ "count" ] = 0
data[ "class" ] = -1
print("data.columns = ", data.columns)
for j in range(0, data.shape[0]):
    tweet_set = set( str(data[ "tweet" ][ j ]).split() )

    pos_count = len(pos_set.intersection( tweet_set ))
    data.at[ j , "positive"] = pos_count
1
  • Please add the complete error message. Commented May 5, 2019 at 5:33

1 Answer 1

1

You want to reset the index:

data.reset_index(inplace=True)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.