1

In following line of code

 X = np.array(df.drop(['label'], 1))

Could you please explain what does number 1 do?

From documentation I understand that DataFrame.drop function drops desired column named 'label' from dataframe and returns new dataframe without this column. But I dont understand what does this particular integer parameter 1 do.

2 Answers 2

3

It is parameter axis in drop. It is same as axis=1. And it means you need remove columns from DataFrame which are specify in first parameter labels:

labels is omited most times.
Parameter axis can be removed if need remove row with index, because by default axis=0. Parameter axis=1 is sometimes replaced by 1, because less text, but it is worse readable.

Sample:

import pandas as pd

df = pd.DataFrame({'label':[1,2,3],
                   'label1':[4,5,6],
                   'label2':[7,8,9]})

print (df)
   label  label1  label2
0      1       4       7
1      2       5       8
2      3       6       9

print (df.drop(['label'], 1))
   label1  label2
0       4       7
1       5       8
2       6       9

#most commonly used
print (df.drop(['label'], axis=1))
   label1  label2
0       4       7
1       5       8
2       6       9

print (df.drop(labels=['label'], axis=1))
   label1  label2
0       4       7
1       5       8
2       6       9
Sign up to request clarification or add additional context in comments.

Comments

0

You wanna drop data called 'age' and you'll have to point it's a column.

So when you drop 'age' from data type

x = np.array(data.drop([predict], 1)).

If age is axis x

x = np.array(data.drop([predict], 0))

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.