0

I am using the assign function to add some new columns to my dataframe which are the derived ones from the existing columns of the database.

here's the code -

train2 = pd.read_excel('output1.xlsx')
X_train = (train2.assign(collegeGPA_new = np.power(2.0,(train2["10percentage"] + train2["12percentage"] + train2["collegeGPA"]))).head())
y_train = X_train.Salary
X_train = X_train.drop(['collegeGPA','CollegeTier','Salary','DOB','SalaryL'], axis=1)

Here, 'train2' is my original dataframe, 'collegeGPA_new' is the newly added column and '10percentage', '12percentage', 'collegeGPA', 'Salary', 'DOB', 'SalaryL' are existing columns of the dataframe.

Now the thing is, my dataframe shrinks surprisingly from (3199,628) to (5,628) after deriving X_train. train2 is having shape (3199,628) whereas X_train is having shape (5,628). Where are the other rows going ? What can be the issue here ?

1
  • 1
    Why is there a .head() at the end of the assign statement? Commented Jan 23, 2016 at 22:36

1 Answer 1

1

DataFrame.head returns only N first rows of the dataframe and the default N is 5. That is why X_train has only 5 rows.

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.