{"cells":[{"metadata":{},"cell_type":"markdown","source":"1st step: Loading of the libraries and listing all of the files in the input directory. \n\nFiles you should see are: \n\n/kaggle/input/riiid-test-answer-prediction/example_test.csv\n/kaggle/input/riiid-test-answer-prediction/lectures.csv\n/kaggle/input/riiid-test-answer-prediction/example_sample_submission.csv\n/kaggle/input/riiid-test-answer-prediction/questions.csv\n/kaggle/input/riiid-test-answer-prediction/train.csv\n/kaggle/input/riiid-test-answer-prediction/riiideducation/competition.cpython-37m-x86_64-linux-gnu.so\n/kaggle/input/riiid-test-answer-prediction/riiideducation/__init__.py"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport sklearn as sk\nimport riiideducation\nfrom sklearn.feature_extraction.text import CountVectorizer\nfrom sklearn.feature_extraction.text import TfidfTransformer\nfrom sklearn.naive_bayes import MultinomialNB\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"2nd Step: Read the train.csv file and generate a table. "},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"train_dataframe = pd.read_csv('/kaggle/input/riiid-test-answer-prediction/train.csv', low_memory=False, nrows=10**5, \n                       dtype={'row_id': 'int64', 'timestamp': 'int64', 'user_id': 'int32', 'content_id': 'int16', 'content_type_id': 'int8',\n                              'task_container_id': 'int16', 'user_answer': 'int8', 'answered_correctly': 'int8', 'prior_question_elapsed_time': 'float32', \n                             'prior_question_had_explanation': 'boolean',\n                             }\n                      )\ntrain_dataframe","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"3rd Step: Print the user_id values deriving from the train.csv file below. "},{"metadata":{"trusted":true},"cell_type":"code","source":"print(train_dataframe['user_id'])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Step 4: Return the table with only columns Content_Id and Answered_Correctly is visible\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"trainWhereContentIdIsZero = train_dataframe[train_dataframe.content_type_id==0]\n\ntrainDFWithContentIdAndAnsweredCorrectly = trainWhereContentIdIsZero[['content_id','answered_correctly']].groupby('content_id')\n\n# Question I have is grouping by ContentId even necessary? We already filtered the train_dataframe to \n# only show where the Content_Type_Id is equal to Zero so this may not even be needed. (N.I.)\n\n\n\n# Did you want to group by the answered correctly values instead? (N.I.)\n\n\n# This will print the first values in each group \ntrainDFWithContentIdAndAnsweredCorrectly.first()\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\ndef prepare_features(col_name):\n    df = train_df[train_df.content_type_id==0][[col_name,'answered_correctly']].groupby(col_name).agg(['count','sum'])\n    df.columns=['total', 'positive']\n    df = df.astype('uint64')\n    df['negative'] = df['total']-df['positive']\n    return df\n    ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"question_df = prepare_features('content_id')\nquestion_df","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.content_id.unique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}