pycharmcode-cleanupfolding

How to fold few selected lines of code in PyCharm IDE?


How can i fold few selected lines of code in PyCharm Ide.

For eg, i want to fold this selected lines of code shown in the image below:

enter image description here

# Importing the dataset
dataset = pd.read_csv('Churn_Modelling.csv')
X = dataset.iloc[:, 3:13].values
y = dataset.iloc[:, 13].values

# Encoding categorical data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X_1 = LabelEncoder()
X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1])
labelencoder_X_2 = LabelEncoder()
X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2])
onehotencoder = OneHotEncoder(categorical_features = [1])
X = onehotencoder.fit_transform(X).toarray()
X = X[:, 1:]

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

Solution

  • I've found Solution to this!!

    Steps:

    1. Select the lines of code you want to fold and press CTRL + .( Ctrl + Dot).

    OR

    1. Right click and navigate to Folding -> click on 'Fold Selection/Remove Region' option.

    Screenshot: enter image description here

    Result:

    enter image description here