1

Very basic issue, but I'm having a hard time figuring out what's wrong. As a result of a Logistic Regression model, I have a set of predictions. I turned that numpy array into a dataframe (single column). Now I want to 'attach' the results to my original data, so I can check my predictions. Seems so simple, but I get the following message:

RuntimeWarning: '<' not supported between instances of 'str' and 'int', sort order is undefined for incomparable objects result = result.union(other)

Sample Looks like this:

Set
ColA, ColB, ColC
1234, AAAA, BBBB

Pred
0 -- column name
1 -- values

Desired result:
ColA, ColB, ColC, 0
1234, AAAA, BBBB, 1

Actual result:
ColA, ColB, ColC, NaN
NaN,  NaN,  NaN,  1

My code seems straightforward:

res = Set.append(Pred)
res

Any help with this issue would be great. As you might see, I am at a beginner level in Pandas...

Regards, M.

1 Answer 1

1

First create default indices:

Set = Set.reset_index(drop=True)
Pred = Pred.reset_index(drop=True)

Then use DataFrame.join:

res = Set.join(Pred)

Or pandas.concat:

res = pd.concat([Set, Pred], axis=1)

Or assign if Pred is Series:

res = Set.assign(Pred=Pred)
Sign up to request clarification or add additional context in comments.

3 Comments

Well, I must be overseeing something, but they all give me the same result. Is my index col (ColA) on Set the issue? Thanks for your input thusfar. Probably all valid options, I must be doing something wrong.
@SQL_M - Yes, it is possible, need Set = Set.reset_index(drop=True) Pred= Pred.reset_index(drop=True) in first step
I reset the index and now it works!! I used the assign method. Thanks!!

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.