The fit, transform and fit_transform method in standard scaler

When I am trying
I get a value error.
Can’t we do feature scaling this way.
for reference, see code below.

Since we cannot view either the dataset, or the error message here, let me assume there are categorical variables in this dataset. Have you accounted for them before applying StandardScaler? Also, it would be helpful if you could show the actual error message.

Hi Rajtilak!
please find the link to code and data set below.
The complete error message is below:

ValueError Traceback (most recent call last)
2 from sklearn.preprocessing import StandardScaler
3 sc = StandardScaler()
----> 4 X_train=sc.fit_transform(X_train)
5 X_test = sc.transform(X_test)

/usr/local/anaconda/lib/python3.6/site-packages/sklearn/ in fit_transform(self, X, y, **fit_params)
569 if y is None:
570 # fit method of arity 1 (unsupervised transformation)
–> 571 return, **fit_params).transform(X)
572 else:
573 # fit method of arity 2 (supervised transformation)

/usr/local/anaconda/lib/python3.6/site-packages/sklearn/preprocessing/ in fit(self, X, y)
667 # Reset internal state before fitting
668 self._reset()
–> 669 return self.partial_fit(X, y)
671 def partial_fit(self, X, y=None):

/usr/local/anaconda/lib/python3.6/site-packages/sklearn/preprocessing/ in partial_fit(self, X, y)
698 X = check_array(X, accept_sparse=(‘csr’, ‘csc’),
699 estimator=self, dtype=FLOAT_DTYPES,
–> 700 force_all_finite=‘allow-nan’)
702 # Even in the case of with_mean=False, we update the mean anyway

/usr/local/anaconda/lib/python3.6/site-packages/sklearn/utils/ in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
529 array = array.astype(dtype, casting=“unsafe”, copy=False)
530 else:
–> 531 array = np.asarray(array, order=order, dtype=dtype)
532 except ComplexWarning:
533 raise ValueError(“Complex data not supported\n”

/usr/local/anaconda/lib/python3.6/site-packages/numpy/core/ in asarray(a, dtype, order)
537 “”"
–> 538 return array(a, dtype, copy=False, order=order)

ValueError: could not convert string to float: ‘B’

I believe here the issue is that you are trying to convert a string into float that is not a valid float number. Please check if these string are actual strings and if you need to encode them before applying StandardScaler on them. You will find the below link helpful:

I have solved it.Thank you.

how do you solve it???