Reputation: 2414
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.
Upvotes: 1
Views: 2306
Reputation: 1
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))
Upvotes: 0
Reputation: 862611
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
Upvotes: 3