From 75381edb560304ea0de27087b50b6b6802ed5d9a Mon Sep 17 00:00:00 2001 From: Yevhenii Poliakov Date: Sun, 14 May 2023 18:01:26 +0200 Subject: [PATCH] update script4.py --- script4.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/script4.py b/script4.py index f6a11ff..e6b3224 100644 --- a/script4.py +++ b/script4.py @@ -5,7 +5,8 @@ from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler # Step 1: Load the dataset -data = pd.read_csv('25k_movies.csv.shuf', error_bad_lines=False) +data = pd.read_csv('25k_movies.csv.shuf') + # Step 2: Preprocess the data features = ['Total Run Time', 'User Rating', 'Genres', 'Director Name', 'Writer Name'] @@ -16,7 +17,12 @@ data = data[features + [target]] data = data.dropna() # Filter out rows with a different number of columns -data = data[data.apply(lambda x: len(x) == 12, axis=1)] +try: + data = data[data.apply(lambda x: len(x) == 12, axis=1)] +except pd.errors.ParserError as e: + print(f"Error occurred while parsing the dataset: {e}") + print("Dropping rows with inconsistent number of columns...") + data = data[data.apply(lambda x: len(x) == 12 if isinstance(x, list) else True, axis=1)] # Convert categorical variables to numerical representations data = pd.get_dummies(data, columns=['Genres', 'Director Name', 'Writer Name'])