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'])