Search code examples
pythondata-sciencegoogle-colaboratory

How to Remove IndentationError: expected an indented block: except ValueError: in Google Colab


Given a dataset I was asked to perform 5 machine learning models on the dataset.

Here is my code:

standard_scaler = StandardScaler()
try:
  X_train=standard_scaler.fit_transform(X_train)
  X_test=standard_scaler.fit_transform(X_test)

except ValueError:

I keep getting

except ValueError:
                 ^
IndentationError: expected an indented block 

Can someone please help me figure out this issue?


Solution

  • You need a block in ValueError:

    standard_scaler = StandardScaler()
    try:
      X_train=standard_scaler.fit_transform(X_train)
      X_test=standard_scaler.fit_transform(X_test)
    except ValueError:
        pass  #or any other value you need