1

When I try to assign LabelEncoder() to label_encoder, I get an error:

SyntaxError: can't assign to operator

However, I assigned LabelEncoder() to label_encoder in the past.
Here is my code:

label_encoder = LabelEncoder()
play-label = label_encoder.fit_transform(play)
Shayan Shafiq
  • 1,447
  • 5
  • 18
  • 25

2 Answers2

4

This is not an issue related to assigning value to a variable. This is a Syntax Error. You haven't followed the proper naming convention to name the variable play-label.

If you try doing something like this :

>>> a-b = 3
  File "<stdin>", line 1
SyntaxError: can't assign to operator

You'll get the same error.
Replace dash - with Underscore _ and it will work fine.
The correct variable name should be play_label. Refer to this link, for an indepth description . Python Naming Convention

desertnaut
  • 57,590
  • 26
  • 140
  • 166
taurus05
  • 2,491
  • 15
  • 28
1

It should be play_label not play-label. You have used the "-" on a variable which is an operator.