{"metadata":{"kernelspec":{"name":"conda-env-anaconda-panel-2023.05-py310-py","display_name":"anaconda-panel-2023.05-py310","language":"python"},"language_info":{"name":"python","version":"3.11.5","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":5,"nbformat":4,"cells":[{"id":"24bb53c7-4128-4603-82f3-53466b1948b6","cell_type":"code","source":"#WEEK 2\n#ACTIVITY 1\nimport pandas as pd \ndata = pd.read_csv('titanic.csv') ","metadata":{"trusted":true},"outputs":[],"execution_count":1},{"id":"fdf00472-9b5f-460c-8749-7a7c7aca0c68","cell_type":"code","source":"data.isnull().sum()","metadata":{"trusted":true},"outputs":[{"execution_count":2,"output_type":"execute_result","data":{"text/plain":"PassengerId      0\nSurvived         0\nPclass           0\nName             0\nSex              0\nAge            177\nSibSp            0\nParch            0\nTicket           0\nFare             0\nCabin          687\nEmbarked         2\ndtype: int64"},"metadata":{}}],"execution_count":2},{"id":"22656029-8f05-42e8-bb5c-edbab97a6cbe","cell_type":"code","source":"data['Age'].fillna(data['Age'].mean(), inplace=True)","metadata":{"trusted":true},"outputs":[],"execution_count":3},{"id":"a1748843-66e5-4c0f-935e-02bc8aef568b","cell_type":"code","source":"data['Age']","metadata":{"trusted":true},"outputs":[{"execution_count":16,"output_type":"execute_result","data":{"text/plain":"0      22.000000\n1      38.000000\n2      26.000000\n3      35.000000\n4      35.000000\n         ...    \n886    27.000000\n887    19.000000\n888    29.699118\n889    26.000000\n890    32.000000\nName: Age, Length: 891, dtype: float64"},"metadata":{}}],"execution_count":16},{"id":"d3fa4602-6d94-4605-aa66-e2ce66b371f7","cell_type":"code","source":"data.drop(columns=['Cabin'], inplace=True)","metadata":{"trusted":true},"outputs":[],"execution_count":4},{"id":"920afbf7-7ecc-4ae5-afce-c9df75136615","cell_type":"code","source":"data[\"Sex\"] = data[\"Sex\"].replace({\"male\": 0, \"female\": 1})\ndata[\"Sex\"]","metadata":{"trusted":true},"outputs":[{"execution_count":15,"output_type":"execute_result","data":{"text/plain":"0      0\n1      1\n2      1\n3      1\n4      0\n      ..\n886    0\n887    1\n888    1\n889    0\n890    0\nName: Sex, Length: 891, dtype: int64"},"metadata":{}}],"execution_count":15},{"id":"c4cc0171-418d-4cc5-969f-873ea819fcf6","cell_type":"code","source":"data.info()","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"<class 'pandas.core.frame.DataFrame'>\nRangeIndex: 891 entries, 0 to 890\nData columns (total 11 columns):\n #   Column       Non-Null Count  Dtype  \n---  ------       --------------  -----  \n 0   PassengerId  891 non-null    int64  \n 1   Survived     891 non-null    int64  \n 2   Pclass       891 non-null    int64  \n 3   Name         891 non-null    object \n 4   Sex          891 non-null    int64  \n 5   Age          891 non-null    float64\n 6   SibSp        891 non-null    int64  \n 7   Parch        891 non-null    int64  \n 8   Ticket       891 non-null    object \n 9   Fare         891 non-null    float64\n 10  Embarked     889 non-null    object \ndtypes: float64(2), int64(6), object(3)\nmemory usage: 76.7+ KB\n"}],"execution_count":17},{"id":"b5523fc2-5f06-4c01-922d-0875c304bdc8","cell_type":"code","source":"data.isnull().sum()","metadata":{"trusted":true},"outputs":[{"execution_count":7,"output_type":"execute_result","data":{"text/plain":"PassengerId    0\nSurvived       0\nPclass         0\nName           0\nSex            0\nAge            0\nSibSp          0\nParch          0\nTicket         0\nFare           0\nEmbarked       2\ndtype: int64"},"metadata":{}}],"execution_count":7},{"id":"f57d1629-adf3-4e71-9dfd-d4181a544f1e","cell_type":"code","source":"data.to_csv(\"cleaned_titanic_data.csv\", index=False)","metadata":{"trusted":true},"outputs":[],"execution_count":18},{"id":"93108894-6b77-454d-81e9-3d2a81cad617","cell_type":"code","source":"data.head()","metadata":{"trusted":true},"outputs":[{"execution_count":24,"output_type":"execute_result","data":{"text/plain":"   PassengerId  Survived  Pclass  \\\n0            1         0       3   \n1            2         1       1   \n2            3         1       3   \n3            4         1       1   \n4            5         0       3   \n\n                                                Name  Sex   Age  SibSp  Parch  \\\n0                           Braund\\t Mr. Owen Harris    0  22.0      1      0   \n1  Cumings\\t Mrs. John Bradley (Florence Briggs T...    1  38.0      1      0   \n2                             Heikkinen\\t Miss Laina    1  26.0      0      0   \n3      Futrelle\\t Mrs. Jacques Heath (Lily May Peel)    1  35.0      1      0   \n4                          Allen\\t Mr. William Henry    0  35.0      0      0   \n\n             Ticket     Fare Embarked  \n0         A/5 21171   7.2500        S  \n1          PC 17599  71.2833        C  \n2  STON/O2. 3101282   7.9250        S  \n3            113803  53.1000        S  \n4            373450   8.0500        S  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>PassengerId</th>\n      <th>Survived</th>\n      <th>Pclass</th>\n      <th>Name</th>\n      <th>Sex</th>\n      <th>Age</th>\n      <th>SibSp</th>\n      <th>Parch</th>\n      <th>Ticket</th>\n      <th>Fare</th>\n      <th>Embarked</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>0</td>\n      <td>3</td>\n      <td>Braund\\t Mr. Owen Harris</td>\n      <td>0</td>\n      <td>22.0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>A/5 21171</td>\n      <td>7.2500</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>1</td>\n      <td>1</td>\n      <td>Cumings\\t Mrs. John Bradley (Florence Briggs T...</td>\n      <td>1</td>\n      <td>38.0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>PC 17599</td>\n      <td>71.2833</td>\n      <td>C</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>3</td>\n      <td>1</td>\n      <td>3</td>\n      <td>Heikkinen\\t Miss Laina</td>\n      <td>1</td>\n      <td>26.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>STON/O2. 3101282</td>\n      <td>7.9250</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>4</td>\n      <td>1</td>\n      <td>1</td>\n      <td>Futrelle\\t Mrs. Jacques Heath (Lily May Peel)</td>\n      <td>1</td>\n      <td>35.0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>113803</td>\n      <td>53.1000</td>\n      <td>S</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>5</td>\n      <td>0</td>\n      <td>3</td>\n      <td>Allen\\t Mr. William Henry</td>\n      <td>0</td>\n      <td>35.0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>373450</td>\n      <td>8.0500</td>\n      <td>S</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}],"execution_count":24},{"id":"ef198a57-f145-47a2-948c-adf523b00bbf","cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}