the syntax getting error solve it please

0 votes

#scaled the data
x = cleaned_df.drop('Churn', axis=1 ) #feature data set
y = cleaned_df['Churn']

x = StandardScaler().fit_transform(x)

ValueError                                Traceback (most recent call last)
<ipython-input-66-5cd9d7ec56d3> in <module>
      3 y = cleaned_df['Churn']
      4 
----> 5 x = StandardScaler().fit_transform(x)

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\base.py in fit_transform(self, X, y, **fit_params)
    569         if y is None:
    570             # fit method of arity 1 (unsupervised transformation)
--> 571             return self.fit(X, **fit_params).transform(X)
    572         else:
    573             # fit method of arity 2 (supervised transformation)

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\_data.py in fit(self, X, y)
    667         # Reset internal state before fitting
    668         self._reset()
--> 669         return self.partial_fit(X, y)
    670 
    671     def partial_fit(self, X, y=None):

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\_data.py 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')
    701 
    702         # Even in the case of `with_mean=False`, we update the mean anyway

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py 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)
    513                     array = array.astype(dtype, casting="unsafe", copy=False)
    514                 else:
--> 515                     array = np.asarray(array, order=order, dtype=dtype)
    516             except ComplexWarning:
    517                 raise ValueError("Complex data not supported\n"

C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\numeric.py in asarray(a, dtype, order)
    536 
    537     """
--> 538     return array(a, dtype, copy=False, order=order)
    539 
    540 

ValueError: could not convert string to float: 'Female'
Jun 18, 2020 in Python by shahzad
• 120 points
1,190 views

1 answer to this question.

0 votes

Hi@shahzad,

Your dataset contains a string value. You can't convert a string to a different value. You have to convert your string values into a dummy variable using the OneHotEncoding method. In pandas one function available named get_dummies. It will convert your string into a numeric value.

answered Jun 18, 2020 by MD
• 95,460 points

Related Questions In Python

0 votes
1 answer

Why am I getting the syntax error SyntaxError invalid syntax in a line that contains fully valid syntax?

A "SyntaxError: invalid syntax" is a common ...READ MORE

answered Oct 18, 2023 in Python by anonymous
• 3,360 points
890 views
0 votes
2 answers

How to solve the error - ssl module not found?

Hey, @There, nstall the necessary packages for Python ...READ MORE

answered Oct 23, 2020 in Python by Gitika
• 65,890 points
2,420 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,350 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,910 views
0 votes
3 answers

i am installing wordcloud using pip but i am unable to do that ....i am getting the following error

word cloud is not supported for python ...READ MORE

answered Apr 15, 2020 in Python by anonymous
32,772 views
0 votes
1 answer

how to solve the error : "ImportError: No module named Tkinter" in python.

Hi@Umama, If you are using Linux system, then ...READ MORE

answered Apr 27, 2020 in Python by MD
• 95,460 points
13,321 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP