Welcome to the Simplilearn Community

Want to join the rest of our members? Sign up right away!

Sign Up

Stuck on 4.18 Demo Bigmart - Machine Learning

I am hoping someone can help me. I am trying to do

so I created a new column called 'Item_Visibility_bins' and wanted to label it low viz, viz, high viz. Based on the values in 'Item_Visibility'

Once I did that it created NaN values in the column which had Item visibility values at 0.0000

train['Item_Visibility_bins'] = pd.cut(train['Item_Visibility'],[0.000, 0.065, 0.13, 0.2], labels=['Low Viz','Viz','High Viz'])

To correct this problem I wanted to replace the nan values with the word 'Low Viz' The code runs without any errors. However the NaN values do not get replaced in the columns. They continue to be NaN values.

train['Item_Visibility_bins'] = train['Item_Visibility_bins'].replace(np.nan,'Low Viz',regex=True)

What am I doing wrong?
 
I am hoping someone can help me. I am trying to do

so I created a new column called 'Item_Visibility_bins' and wanted to label it low viz, viz, high viz. Based on the values in 'Item_Visibility'

Once I did that it created NaN values in the column which had Item visibility values at 0.0000

train['Item_Visibility_bins'] = pd.cut(train['Item_Visibility'],[0.000, 0.065, 0.13, 0.2], labels=['Low Viz','Viz','High Viz'])

To correct this problem I wanted to replace the nan values with the word 'Low Viz' The code runs without any errors. However the NaN values do not get replaced in the columns. They continue to be NaN values.

train['Item_Visibility_bins'] = train['Item_Visibility_bins'].replace(np.nan,'Low Viz',regex=True)

What am I doing wrong?
Hey Pawel!
It is probably too late but if you go a few lines above were you define train['Item_Visibility_bins']:
"train['Item_Visibility_bins'] = pd.cut(train['Item_Visibility'],[0.000, 0.065, 0.13, 0.2], labels=['Low Viz','Viz','High Viz'])"
change the first low bracket by replacing the 0.000 with -0.01.
The values in that array are between 0 and 0.2. so ... you should be good!
 
Top