{ "cells": [ { "cell_type": "code", "execution_count": 93, "id": "8a95934e-ff3f-41b1-be3a-c63b4f625c9e", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 95, "id": "9cf17eea-09e2-4e51-9c59-bd13453b81cd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idGenderAgeCityProfessionAcademic PressureWork PressureCGPAStudy SatisfactionJob SatisfactionSleep DurationDietary HabitsDegreeHave you ever had suicidal thoughts ?Work/Study HoursFinancial StressFamily History of Mental IllnessDepression
02Male33.0VisakhapatnamStudent5.00.08.972.00.0'5-6 hours'HealthyB.PharmYes3.01.0No1
18Female24.0BangaloreStudent2.00.05.905.00.0'5-6 hours'ModerateBScNo3.02.0Yes0
226Male31.0SrinagarStudent3.00.07.035.00.0'Less than 5 hours'HealthyBANo9.01.0Yes0
330Female28.0VaranasiStudent3.00.05.592.00.0'7-8 hours'ModerateBCAYes4.05.0Yes1
432Female25.0JaipurStudent4.00.08.133.00.0'5-6 hours'ModerateM.TechYes1.01.0No0
.........................................................
27896140685Female27.0SuratStudent5.00.05.755.00.0'5-6 hours'Unhealthy'Class 12'Yes7.01.0Yes0
27897140686Male27.0LudhianaStudent2.00.09.403.00.0'Less than 5 hours'HealthyMScNo0.03.0Yes0
27898140689Male31.0FaridabadStudent3.00.06.614.00.0'5-6 hours'UnhealthyMDNo12.02.0No0
27899140690Female18.0LudhianaStudent5.00.06.882.00.0'Less than 5 hours'Healthy'Class 12'Yes10.05.0No1
27900140699Male27.0PatnaStudent4.00.09.241.00.0'Less than 5 hours'HealthyBCAYes2.03.0Yes1
\n", "

27901 rows × 18 columns

\n", "
" ], "text/plain": [ " id Gender Age City Profession Academic Pressure \\\n", "0 2 Male 33.0 Visakhapatnam Student 5.0 \n", "1 8 Female 24.0 Bangalore Student 2.0 \n", "2 26 Male 31.0 Srinagar Student 3.0 \n", "3 30 Female 28.0 Varanasi Student 3.0 \n", "4 32 Female 25.0 Jaipur Student 4.0 \n", "... ... ... ... ... ... ... \n", "27896 140685 Female 27.0 Surat Student 5.0 \n", "27897 140686 Male 27.0 Ludhiana Student 2.0 \n", "27898 140689 Male 31.0 Faridabad Student 3.0 \n", "27899 140690 Female 18.0 Ludhiana Student 5.0 \n", "27900 140699 Male 27.0 Patna Student 4.0 \n", "\n", " Work Pressure CGPA Study Satisfaction Job Satisfaction \\\n", "0 0.0 8.97 2.0 0.0 \n", "1 0.0 5.90 5.0 0.0 \n", "2 0.0 7.03 5.0 0.0 \n", "3 0.0 5.59 2.0 0.0 \n", "4 0.0 8.13 3.0 0.0 \n", "... ... ... ... ... \n", "27896 0.0 5.75 5.0 0.0 \n", "27897 0.0 9.40 3.0 0.0 \n", "27898 0.0 6.61 4.0 0.0 \n", "27899 0.0 6.88 2.0 0.0 \n", "27900 0.0 9.24 1.0 0.0 \n", "\n", " Sleep Duration Dietary Habits Degree \\\n", "0 '5-6 hours' Healthy B.Pharm \n", "1 '5-6 hours' Moderate BSc \n", "2 'Less than 5 hours' Healthy BA \n", "3 '7-8 hours' Moderate BCA \n", "4 '5-6 hours' Moderate M.Tech \n", "... ... ... ... \n", "27896 '5-6 hours' Unhealthy 'Class 12' \n", "27897 'Less than 5 hours' Healthy MSc \n", "27898 '5-6 hours' Unhealthy MD \n", "27899 'Less than 5 hours' Healthy 'Class 12' \n", "27900 'Less than 5 hours' Healthy BCA \n", "\n", " Have you ever had suicidal thoughts ? Work/Study Hours \\\n", "0 Yes 3.0 \n", "1 No 3.0 \n", "2 No 9.0 \n", "3 Yes 4.0 \n", "4 Yes 1.0 \n", "... ... ... \n", "27896 Yes 7.0 \n", "27897 No 0.0 \n", "27898 No 12.0 \n", "27899 Yes 10.0 \n", "27900 Yes 2.0 \n", "\n", " Financial Stress Family History of Mental Illness Depression \n", "0 1.0 No 1 \n", "1 2.0 Yes 0 \n", "2 1.0 Yes 0 \n", "3 5.0 Yes 1 \n", "4 1.0 No 0 \n", "... ... ... ... \n", "27896 1.0 Yes 0 \n", "27897 3.0 Yes 0 \n", "27898 2.0 No 0 \n", "27899 5.0 No 1 \n", "27900 3.0 Yes 1 \n", "\n", "[27901 rows x 18 columns]" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_csv(r\"C:\\Users\\pavilion\\Desktop\\INNOMATICS\\Student_Depresion_Prediction(Machine_Learning)\\student_depression_dataset.csv\")\n", "df" ] }, { "cell_type": "code", "execution_count": 143, "id": "4e969e45-7a97-4c43-986a-7c34ce18682e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idGenderAgeCityProfessionAcademic PressureWork PressureCGPAStudy SatisfactionJob SatisfactionSleep DurationDietary HabitsDegreeHave you ever had suicidal thoughts ?Work/Study HoursFinancial StressFamily History of Mental IllnessDepression
02Male33.0VisakhapatnamStudent5.00.08.972.00.0'5-6 hours'HealthyB.PharmYes3.01.0No1
18Female24.0BangaloreStudent2.00.05.905.00.0'5-6 hours'ModerateBScNo3.02.0Yes0
226Male31.0SrinagarStudent3.00.07.035.00.0'Less than 5 hours'HealthyBANo9.01.0Yes0
330Female28.0VaranasiStudent3.00.05.592.00.0'7-8 hours'ModerateBCAYes4.05.0Yes1
432Female25.0JaipurStudent4.00.08.133.00.0'5-6 hours'ModerateM.TechYes1.01.0No0
.........................................................
27865140685Female27.0SuratStudent5.00.05.755.00.0'5-6 hours'Unhealthy'Class 12'Yes7.01.0Yes0
27866140686Male27.0LudhianaStudent2.00.09.403.00.0'Less than 5 hours'HealthyMScNo0.03.0Yes0
27867140689Male31.0FaridabadStudent3.00.06.614.00.0'5-6 hours'UnhealthyMDNo12.02.0No0
27868140690Female18.0LudhianaStudent5.00.06.882.00.0'Less than 5 hours'Healthy'Class 12'Yes10.05.0No1
27869140699Male27.0PatnaStudent4.00.09.241.00.0'Less than 5 hours'HealthyBCAYes2.03.0Yes1
\n", "

27870 rows × 18 columns

\n", "
" ], "text/plain": [ " id Gender Age City Profession Academic Pressure \\\n", "0 2 Male 33.0 Visakhapatnam Student 5.0 \n", "1 8 Female 24.0 Bangalore Student 2.0 \n", "2 26 Male 31.0 Srinagar Student 3.0 \n", "3 30 Female 28.0 Varanasi Student 3.0 \n", "4 32 Female 25.0 Jaipur Student 4.0 \n", "... ... ... ... ... ... ... \n", "27865 140685 Female 27.0 Surat Student 5.0 \n", "27866 140686 Male 27.0 Ludhiana Student 2.0 \n", "27867 140689 Male 31.0 Faridabad Student 3.0 \n", "27868 140690 Female 18.0 Ludhiana Student 5.0 \n", "27869 140699 Male 27.0 Patna Student 4.0 \n", "\n", " Work Pressure CGPA Study Satisfaction Job Satisfaction \\\n", "0 0.0 8.97 2.0 0.0 \n", "1 0.0 5.90 5.0 0.0 \n", "2 0.0 7.03 5.0 0.0 \n", "3 0.0 5.59 2.0 0.0 \n", "4 0.0 8.13 3.0 0.0 \n", "... ... ... ... ... \n", "27865 0.0 5.75 5.0 0.0 \n", "27866 0.0 9.40 3.0 0.0 \n", "27867 0.0 6.61 4.0 0.0 \n", "27868 0.0 6.88 2.0 0.0 \n", "27869 0.0 9.24 1.0 0.0 \n", "\n", " Sleep Duration Dietary Habits Degree \\\n", "0 '5-6 hours' Healthy B.Pharm \n", "1 '5-6 hours' Moderate BSc \n", "2 'Less than 5 hours' Healthy BA \n", "3 '7-8 hours' Moderate BCA \n", "4 '5-6 hours' Moderate M.Tech \n", "... ... ... ... \n", "27865 '5-6 hours' Unhealthy 'Class 12' \n", "27866 'Less than 5 hours' Healthy MSc \n", "27867 '5-6 hours' Unhealthy MD \n", "27868 'Less than 5 hours' Healthy 'Class 12' \n", "27869 'Less than 5 hours' Healthy BCA \n", "\n", " Have you ever had suicidal thoughts ? Work/Study Hours \\\n", "0 Yes 3.0 \n", "1 No 3.0 \n", "2 No 9.0 \n", "3 Yes 4.0 \n", "4 Yes 1.0 \n", "... ... ... \n", "27865 Yes 7.0 \n", "27866 No 0.0 \n", "27867 No 12.0 \n", "27868 Yes 10.0 \n", "27869 Yes 2.0 \n", "\n", " Financial Stress Family History of Mental Illness Depression \n", "0 1.0 No 1 \n", "1 2.0 Yes 0 \n", "2 1.0 Yes 0 \n", "3 5.0 Yes 1 \n", "4 1.0 No 0 \n", "... ... ... ... \n", "27865 1.0 Yes 0 \n", "27866 3.0 Yes 0 \n", "27867 2.0 No 0 \n", "27868 5.0 No 1 \n", "27869 3.0 Yes 1 \n", "\n", "[27870 rows x 18 columns]" ] }, "execution_count": 143, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df1 = df.loc[df[\"Profession\"]==\"Student\"].reset_index(drop=True)\n", "df1" ] }, { "cell_type": "code", "execution_count": 145, "id": "f51d9817-8b49-40d0-821c-35baf4cdfb88", "metadata": {}, "outputs": [], "source": [ "df1.to_csv(\"Student_Depresion_Prediction.csv\")" ] }, { "cell_type": "code", "execution_count": 152, "id": "1cead9da-c26b-408f-9fbc-bb2fb93c92a2", "metadata": {}, "outputs": [], "source": [ "df1.drop(columns=[\"id\", \"City\", \"Job Satisfaction\", \"Work Pressure\"], inplace=True)" ] }, { "cell_type": "code", "execution_count": 156, "id": "0c8970ce-68a1-492f-9b0c-fae93e8dd4fe", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
GenderAgeProfessionAcademic PressureCGPAStudy SatisfactionSleep DurationDietary HabitsDegreeHave you ever had suicidal thoughts ?Work/Study HoursFinancial StressFamily History of Mental IllnessDepression
0Male33.0Student5.08.972.0'5-6 hours'HealthyB.PharmYes3.01.0No1
1Female24.0Student2.05.905.0'5-6 hours'ModerateBScNo3.02.0Yes0
2Male31.0Student3.07.035.0'Less than 5 hours'HealthyBANo9.01.0Yes0
3Female28.0Student3.05.592.0'7-8 hours'ModerateBCAYes4.05.0Yes1
4Female25.0Student4.08.133.0'5-6 hours'ModerateM.TechYes1.01.0No0
.............................................
27865Female27.0Student5.05.755.0'5-6 hours'Unhealthy'Class 12'Yes7.01.0Yes0
27866Male27.0Student2.09.403.0'Less than 5 hours'HealthyMScNo0.03.0Yes0
27867Male31.0Student3.06.614.0'5-6 hours'UnhealthyMDNo12.02.0No0
27868Female18.0Student5.06.882.0'Less than 5 hours'Healthy'Class 12'Yes10.05.0No1
27869Male27.0Student4.09.241.0'Less than 5 hours'HealthyBCAYes2.03.0Yes1
\n", "

27870 rows × 14 columns

\n", "
" ], "text/plain": [ " Gender Age Profession Academic Pressure CGPA Study Satisfaction \\\n", "0 Male 33.0 Student 5.0 8.97 2.0 \n", "1 Female 24.0 Student 2.0 5.90 5.0 \n", "2 Male 31.0 Student 3.0 7.03 5.0 \n", "3 Female 28.0 Student 3.0 5.59 2.0 \n", "4 Female 25.0 Student 4.0 8.13 3.0 \n", "... ... ... ... ... ... ... \n", "27865 Female 27.0 Student 5.0 5.75 5.0 \n", "27866 Male 27.0 Student 2.0 9.40 3.0 \n", "27867 Male 31.0 Student 3.0 6.61 4.0 \n", "27868 Female 18.0 Student 5.0 6.88 2.0 \n", "27869 Male 27.0 Student 4.0 9.24 1.0 \n", "\n", " Sleep Duration Dietary Habits Degree \\\n", "0 '5-6 hours' Healthy B.Pharm \n", "1 '5-6 hours' Moderate BSc \n", "2 'Less than 5 hours' Healthy BA \n", "3 '7-8 hours' Moderate BCA \n", "4 '5-6 hours' Moderate M.Tech \n", "... ... ... ... \n", "27865 '5-6 hours' Unhealthy 'Class 12' \n", "27866 'Less than 5 hours' Healthy MSc \n", "27867 '5-6 hours' Unhealthy MD \n", "27868 'Less than 5 hours' Healthy 'Class 12' \n", "27869 'Less than 5 hours' Healthy BCA \n", "\n", " Have you ever had suicidal thoughts ? Work/Study Hours \\\n", "0 Yes 3.0 \n", "1 No 3.0 \n", "2 No 9.0 \n", "3 Yes 4.0 \n", "4 Yes 1.0 \n", "... ... ... \n", "27865 Yes 7.0 \n", "27866 No 0.0 \n", "27867 No 12.0 \n", "27868 Yes 10.0 \n", "27869 Yes 2.0 \n", "\n", " Financial Stress Family History of Mental Illness Depression \n", "0 1.0 No 1 \n", "1 2.0 Yes 0 \n", "2 1.0 Yes 0 \n", "3 5.0 Yes 1 \n", "4 1.0 No 0 \n", "... ... ... ... \n", "27865 1.0 Yes 0 \n", "27866 3.0 Yes 0 \n", "27867 2.0 No 0 \n", "27868 5.0 No 1 \n", "27869 3.0 Yes 1 \n", "\n", "[27870 rows x 14 columns]" ] }, "execution_count": 156, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df1" ] }, { "cell_type": "code", "execution_count": 158, "id": "8b272d83-19d8-4f89-97e9-d3d02e4d55fd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(27870, 14)" ] }, "execution_count": 158, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df1.shape" ] }, { "cell_type": "code", "execution_count": 162, "id": "fbf8de3f-dd98-4613-b3f1-5f2a48e0c7e1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 27870 entries, 0 to 27869\n", "Data columns (total 14 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 Gender 27870 non-null object \n", " 1 Age 27870 non-null float64\n", " 2 Profession 27870 non-null object \n", " 3 Academic Pressure 27870 non-null float64\n", " 4 CGPA 27870 non-null float64\n", " 5 Study Satisfaction 27870 non-null float64\n", " 6 Sleep Duration 27870 non-null object \n", " 7 Dietary Habits 27870 non-null object \n", " 8 Degree 27870 non-null object \n", " 9 Have you ever had suicidal thoughts ? 27870 non-null object \n", " 10 Work/Study Hours 27870 non-null float64\n", " 11 Financial Stress 27870 non-null object \n", " 12 Family History of Mental Illness 27870 non-null object \n", " 13 Depression 27870 non-null int64 \n", "dtypes: float64(5), int64(1), object(8)\n", "memory usage: 3.0+ MB\n" ] } ], "source": [ "df1.info()" ] }, { "cell_type": "code", "execution_count": 166, "id": "0a47a407-c42c-485d-8ecf-002ff4eb1d33", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
GenderAgeProfessionAcademic PressureCGPAStudy SatisfactionSleep DurationDietary HabitsDegreeHave you ever had suicidal thoughts ?Work/Study HoursFinancial StressFamily History of Mental IllnessDepression
0Male33.0Student5.08.972.0'5-6 hours'HealthyB.PharmYes3.01.0No1
1Female24.0Student2.05.905.0'5-6 hours'ModerateBScNo3.02.0Yes0
2Male31.0Student3.07.035.0'Less than 5 hours'HealthyBANo9.01.0Yes0
3Female28.0Student3.05.592.0'7-8 hours'ModerateBCAYes4.05.0Yes1
4Female25.0Student4.08.133.0'5-6 hours'ModerateM.TechYes1.01.0No0
.............................................
27865Female27.0Student5.05.755.0'5-6 hours'Unhealthy'Class 12'Yes7.01.0Yes0
27866Male27.0Student2.09.403.0'Less than 5 hours'HealthyMScNo0.03.0Yes0
27867Male31.0Student3.06.614.0'5-6 hours'UnhealthyMDNo12.02.0No0
27868Female18.0Student5.06.882.0'Less than 5 hours'Healthy'Class 12'Yes10.05.0No1
27869Male27.0Student4.09.241.0'Less than 5 hours'HealthyBCAYes2.03.0Yes1
\n", "

27870 rows × 14 columns

\n", "
" ], "text/plain": [ " Gender Age Profession Academic Pressure CGPA Study Satisfaction \\\n", "0 Male 33.0 Student 5.0 8.97 2.0 \n", "1 Female 24.0 Student 2.0 5.90 5.0 \n", "2 Male 31.0 Student 3.0 7.03 5.0 \n", "3 Female 28.0 Student 3.0 5.59 2.0 \n", "4 Female 25.0 Student 4.0 8.13 3.0 \n", "... ... ... ... ... ... ... \n", "27865 Female 27.0 Student 5.0 5.75 5.0 \n", "27866 Male 27.0 Student 2.0 9.40 3.0 \n", "27867 Male 31.0 Student 3.0 6.61 4.0 \n", "27868 Female 18.0 Student 5.0 6.88 2.0 \n", "27869 Male 27.0 Student 4.0 9.24 1.0 \n", "\n", " Sleep Duration Dietary Habits Degree \\\n", "0 '5-6 hours' Healthy B.Pharm \n", "1 '5-6 hours' Moderate BSc \n", "2 'Less than 5 hours' Healthy BA \n", "3 '7-8 hours' Moderate BCA \n", "4 '5-6 hours' Moderate M.Tech \n", "... ... ... ... \n", "27865 '5-6 hours' Unhealthy 'Class 12' \n", "27866 'Less than 5 hours' Healthy MSc \n", "27867 '5-6 hours' Unhealthy MD \n", "27868 'Less than 5 hours' Healthy 'Class 12' \n", "27869 'Less than 5 hours' Healthy BCA \n", "\n", " Have you ever had suicidal thoughts ? Work/Study Hours \\\n", "0 Yes 3.0 \n", "1 No 3.0 \n", "2 No 9.0 \n", "3 Yes 4.0 \n", "4 Yes 1.0 \n", "... ... ... \n", "27865 Yes 7.0 \n", "27866 No 0.0 \n", "27867 No 12.0 \n", "27868 Yes 10.0 \n", "27869 Yes 2.0 \n", "\n", " Financial Stress Family History of Mental Illness Depression \n", "0 1.0 No 1 \n", "1 2.0 Yes 0 \n", "2 1.0 Yes 0 \n", "3 5.0 Yes 1 \n", "4 1.0 No 0 \n", "... ... ... ... \n", "27865 1.0 Yes 0 \n", "27866 3.0 Yes 0 \n", "27867 2.0 No 0 \n", "27868 5.0 No 1 \n", "27869 3.0 Yes 1 \n", "\n", "[27870 rows x 14 columns]" ] }, "execution_count": 166, "metadata": {}, "output_type": "execute_result" } ], "source": [ "duplicates = df1.duplicated().sum()\n", "df1 = df1.drop_duplicates().reset_index(drop=True)\n", "df1" ] }, { "cell_type": "code", "execution_count": 183, "id": "82476012-5849-4a29-93c8-8bed0e24d7bf", "metadata": {}, "outputs": [], "source": [ "df1[\"Sleep Duration\"] = df1[\"Sleep Duration\"].str.replace(\"'\", \"\", regex=False)\n", "df1[\"Degree\"] = df1[\"Degree\"].str.replace(\"'\", \"\", regex=False)\n", "\n", "df1[\"Financial Stress\"] = df1[\"Financial Stress\"].replace(\"?\", df1[\"Financial Stress\"].mode()[0])" ] }, { "cell_type": "code", "execution_count": 178, "id": "5c5f1d7d-7061-45dd-8a3c-86f9a090ab33", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
GenderAgeProfessionAcademic PressureCGPAStudy SatisfactionSleep DurationDietary HabitsDegreeHave you ever had suicidal thoughts ?Work/Study HoursFinancial StressFamily History of Mental IllnessDepression
0Male33.0Student5.08.972.05-6 hoursHealthyB.PharmYes3.01.0No1
1Female24.0Student2.05.905.05-6 hoursModerateBScNo3.02.0Yes0
2Male31.0Student3.07.035.0Less than 5 hoursHealthyBANo9.01.0Yes0
3Female28.0Student3.05.592.07-8 hoursModerateBCAYes4.05.0Yes1
4Female25.0Student4.08.133.05-6 hoursModerateM.TechYes1.01.0No0
.............................................
27865Female27.0Student5.05.755.05-6 hoursUnhealthy'Class 12'Yes7.01.0Yes0
27866Male27.0Student2.09.403.0Less than 5 hoursHealthyMScNo0.03.0Yes0
27867Male31.0Student3.06.614.05-6 hoursUnhealthyMDNo12.02.0No0
27868Female18.0Student5.06.882.0Less than 5 hoursHealthy'Class 12'Yes10.05.0No1
27869Male27.0Student4.09.241.0Less than 5 hoursHealthyBCAYes2.03.0Yes1
\n", "

27870 rows × 14 columns

\n", "
" ], "text/plain": [ " Gender Age Profession Academic Pressure CGPA Study Satisfaction \\\n", "0 Male 33.0 Student 5.0 8.97 2.0 \n", "1 Female 24.0 Student 2.0 5.90 5.0 \n", "2 Male 31.0 Student 3.0 7.03 5.0 \n", "3 Female 28.0 Student 3.0 5.59 2.0 \n", "4 Female 25.0 Student 4.0 8.13 3.0 \n", "... ... ... ... ... ... ... \n", "27865 Female 27.0 Student 5.0 5.75 5.0 \n", "27866 Male 27.0 Student 2.0 9.40 3.0 \n", "27867 Male 31.0 Student 3.0 6.61 4.0 \n", "27868 Female 18.0 Student 5.0 6.88 2.0 \n", "27869 Male 27.0 Student 4.0 9.24 1.0 \n", "\n", " Sleep Duration Dietary Habits Degree \\\n", "0 5-6 hours Healthy B.Pharm \n", "1 5-6 hours Moderate BSc \n", "2 Less than 5 hours Healthy BA \n", "3 7-8 hours Moderate BCA \n", "4 5-6 hours Moderate M.Tech \n", "... ... ... ... \n", "27865 5-6 hours Unhealthy 'Class 12' \n", "27866 Less than 5 hours Healthy MSc \n", "27867 5-6 hours Unhealthy MD \n", "27868 Less than 5 hours Healthy 'Class 12' \n", "27869 Less than 5 hours Healthy BCA \n", "\n", " Have you ever had suicidal thoughts ? Work/Study Hours \\\n", "0 Yes 3.0 \n", "1 No 3.0 \n", "2 No 9.0 \n", "3 Yes 4.0 \n", "4 Yes 1.0 \n", "... ... ... \n", "27865 Yes 7.0 \n", "27866 No 0.0 \n", "27867 No 12.0 \n", "27868 Yes 10.0 \n", "27869 Yes 2.0 \n", "\n", " Financial Stress Family History of Mental Illness Depression \n", "0 1.0 No 1 \n", "1 2.0 Yes 0 \n", "2 1.0 Yes 0 \n", "3 5.0 Yes 1 \n", "4 1.0 No 0 \n", "... ... ... ... \n", "27865 1.0 Yes 0 \n", "27866 3.0 Yes 0 \n", "27867 2.0 No 0 \n", "27868 5.0 No 1 \n", "27869 3.0 Yes 1 \n", "\n", "[27870 rows x 14 columns]" ] }, "execution_count": 178, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df1" ] }, { "cell_type": "code", "execution_count": 185, "id": "c55b07cc-488d-44a3-a782-a11d3e5031eb", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gender: ['Male' 'Female']\n", "Profession: ['Student']\n", "Sleep Duration: ['5-6 hours' 'Less than 5 hours' '7-8 hours' 'More than 8 hours' 'Others']\n", "Dietary Habits: ['Healthy' 'Moderate' 'Unhealthy' 'Others']\n", "Degree: ['B.Pharm' 'BSc' 'BA' 'BCA' 'M.Tech' 'PhD' 'Class 12' 'B.Ed' 'LLB' 'BE'\n", " 'M.Ed' 'MSc' 'BHM' 'M.Pharm' 'MCA' 'MA' 'B.Com' 'MD' 'MBA' 'MBBS' 'M.Com'\n", " 'B.Arch' 'LLM' 'B.Tech' 'BBA' 'ME' 'MHM' 'Others']\n", "Have you ever had suicidal thoughts ?: ['Yes' 'No']\n", "Financial Stress: ['1.0' '2.0' '5.0' '3.0' '4.0']\n", "Family History of Mental Illness: ['No' 'Yes']\n" ] } ], "source": [ "for col in df1.select_dtypes(include=['object']).columns:\n", " print(f\"{col}: {df1[col].unique()}\")" ] }, { "cell_type": "code", "execution_count": 189, "id": "aace3557-1ce9-4c9c-841b-5507bbd5ca4b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Gender 0\n", "Age 0\n", "Profession 0\n", "Academic Pressure 0\n", "CGPA 0\n", "Study Satisfaction 0\n", "Sleep Duration 0\n", "Dietary Habits 0\n", "Degree 0\n", "Have you ever had suicidal thoughts ? 0\n", "Work/Study Hours 0\n", "Financial Stress 0\n", "Family History of Mental Illness 0\n", "Depression 0\n", "dtype: int64" ] }, "execution_count": 189, "metadata": {}, "output_type": "execute_result" } ], "source": [ "missing_values = df1.isnull().sum()\n", "missing_values" ] }, { "cell_type": "code", "execution_count": 201, "id": "87e2b5d3-fa7d-4cc4-ac3c-8de0a1a4dd8b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 3.0\n", "1 3.0\n", "2 9.0\n", "3 4.0\n", "4 1.0\n", " ... \n", "27865 7.0\n", "27866 0.0\n", "27867 12.0\n", "27868 10.0\n", "27869 2.0\n", "Name: Work/Study Hours, Length: 27870, dtype: float64" ] }, "execution_count": 201, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# outliers\n", "\n", "from scipy.stats.mstats import winsorize\n", "numerical_cols = [\"Age\", \"Academic Pressure\", \"CGPA\", \"Study Satisfaction\", \"Work/Study Hours\"]\n", "for col in numerical_cols:\n", " df1[col] = winsorize(df1[col], limits=[0.05, 0.05])\n", "\n", "df1[col]" ] }, { "cell_type": "code", "execution_count": 209, "id": "e84385ca-f0b5-4dc7-8da7-ea89626330c1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
AgeAcademic PressureCGPAStudy SatisfactionWork/Study Hours
00.8888891.00.456274-0.5-0.833333
1-0.111111-0.5-0.7110271.0-0.833333
20.6666670.0-0.2813691.00.166667
30.3333330.0-0.828897-0.5-0.666667
40.0000000.50.1368820.0-1.166667
..................
278650.2222221.0-0.7680611.0-0.166667
278660.222222-0.50.6197720.0-1.333333
278670.6666670.0-0.4410650.50.666667
27868-0.7777781.0-0.338403-0.50.333333
278690.2222220.50.558935-1.0-1.000000
\n", "

27870 rows × 5 columns

\n", "
" ], "text/plain": [ " Age Academic Pressure CGPA Study Satisfaction \\\n", "0 0.888889 1.0 0.456274 -0.5 \n", "1 -0.111111 -0.5 -0.711027 1.0 \n", "2 0.666667 0.0 -0.281369 1.0 \n", "3 0.333333 0.0 -0.828897 -0.5 \n", "4 0.000000 0.5 0.136882 0.0 \n", "... ... ... ... ... \n", "27865 0.222222 1.0 -0.768061 1.0 \n", "27866 0.222222 -0.5 0.619772 0.0 \n", "27867 0.666667 0.0 -0.441065 0.5 \n", "27868 -0.777778 1.0 -0.338403 -0.5 \n", "27869 0.222222 0.5 0.558935 -1.0 \n", "\n", " Work/Study Hours \n", "0 -0.833333 \n", "1 -0.833333 \n", "2 0.166667 \n", "3 -0.666667 \n", "4 -1.166667 \n", "... ... \n", "27865 -0.166667 \n", "27866 -1.333333 \n", "27867 0.666667 \n", "27868 0.333333 \n", "27869 -1.000000 \n", "\n", "[27870 rows x 5 columns]" ] }, "execution_count": 209, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from sklearn.preprocessing import RobustScaler\n", "scaler = RobustScaler()\n", "df1[numerical_cols] = scaler.fit_transform(df1[numerical_cols])\n", "df1[numerical_cols]" ] }, { "cell_type": "code", "execution_count": 211, "id": "1c0d1179-8363-4f40-88d7-54f63f898bc0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
AgeAcademic PressureCGPAStudy SatisfactionWork/Study Hours
count27870.00000027870.00000027870.00000027870.00000027870.000000
mean0.0899100.070470-0.040597-0.028041-0.140342
std0.5411980.6905110.5501200.6802830.617863
min-0.777778-1.000000-0.908745-1.000000-1.333333
25%-0.444444-0.500000-0.562738-0.500000-0.666667
50%0.0000000.0000000.0000000.0000000.000000
75%0.5555560.5000000.4372620.5000000.333333
max1.0000001.0000000.8060841.0000000.666667
\n", "
" ], "text/plain": [ " Age Academic Pressure CGPA Study Satisfaction \\\n", "count 27870.000000 27870.000000 27870.000000 27870.000000 \n", "mean 0.089910 0.070470 -0.040597 -0.028041 \n", "std 0.541198 0.690511 0.550120 0.680283 \n", "min -0.777778 -1.000000 -0.908745 -1.000000 \n", "25% -0.444444 -0.500000 -0.562738 -0.500000 \n", "50% 0.000000 0.000000 0.000000 0.000000 \n", "75% 0.555556 0.500000 0.437262 0.500000 \n", "max 1.000000 1.000000 0.806084 1.000000 \n", "\n", " Work/Study Hours \n", "count 27870.000000 \n", "mean -0.140342 \n", "std 0.617863 \n", "min -1.333333 \n", "25% -0.666667 \n", "50% 0.000000 \n", "75% 0.333333 \n", "max 0.666667 " ] }, "execution_count": 211, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df1[numerical_cols].describe()" ] }, { "cell_type": "code", "execution_count": null, "id": "f10ac51a-c19d-4a75-860f-a6e048351b45", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.4" } }, "nbformat": 4, "nbformat_minor": 5 }