{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Fictitious Names" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Introduction:\n", "\n", "This time you will create a data again \n", "\n", "Special thanks to [Chris Albon](http://chrisalbon.com/) for sharing the dataset and materials.\n", "All the credits to this exercise belongs to him. \n", "\n", "In order to understand about it go [here](https://blog.codinghorror.com/a-visual-explanation-of-sql-joins/).\n", "\n", "### Step 1. Import the necessary libraries" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 2. Create the 3 DataFrames based on the followin raw data" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "raw_data_1 = {\n", " 'subject_id': ['1', '2', '3', '4', '5'],\n", " 'first_name': ['Alex', 'Amy', 'Allen', 'Alice', 'Ayoung'], \n", " 'last_name': ['Anderson', 'Ackerman', 'Ali', 'Aoni', 'Atiches']}\n", "\n", "raw_data_2 = {\n", " 'subject_id': ['4', '5', '6', '7', '8'],\n", " 'first_name': ['Billy', 'Brian', 'Bran', 'Bryce', 'Betty'], \n", " 'last_name': ['Bonder', 'Black', 'Balwner', 'Brice', 'Btisan']}\n", "\n", "raw_data_3 = {\n", " 'subject_id': ['1', '2', '3', '4', '5', '7', '8', '9', '10', '11'],\n", " 'test_id': [51, 15, 15, 61, 16, 14, 15, 1, 61, 16]}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 3. Assign each to a variable called data1, data2, data3" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 4. Join the two dataframes along rows and assign all_data" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 5. Join the two dataframes along columns and assing to all_data_col" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 6. Print data3" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 7. Merge all_data and data3 along the subject_id value" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 8. Merge only the data that has the same 'subject_id' on both data1 and data2" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 9. Merge all values in data1 and data2, with matching records from both sides where available." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11" } }, "nbformat": 4, "nbformat_minor": 0 }