{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "Manipulating the data with Pandas using Python.ipynb", "version": "0.3.2", "provenance": [], "collapsed_sections": [], "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "id": "yNQgzOvVTnux", "colab_type": "text" }, "source": [ "# Manipulating the data with Pandas using Python." ] }, { "cell_type": "markdown", "metadata": { "id": "T-UeD-vYSHjD", "colab_type": "text" }, "source": [ "## Let us calculate my part-time earnings with Pandas DataFrame using Python" ] }, { "cell_type": "markdown", "metadata": { "id": "pXfAnb4mUXSY", "colab_type": "text" }, "source": [ "![alt text](http://i68.tinypic.com/6ft5c8.png)\n" ] }, { "cell_type": "markdown", "metadata": { "id": "_-aVV0ZiSNdS", "colab_type": "text" }, "source": [ "Before getting started let me introduce you [Pandas](https://pandas.pydata.org), Pandas is a python library which provided high-performance, easy to use data structures such as series, Data Frame and Panel for data analysis tools for Python programming language. In order to use the pandas library and its data structures all, you have to do it to install it and import it. See the documentation of the [Pandas](https://pandas.pydata.org) library for more better understanding and installing guidance." ] }, { "cell_type": "markdown", "metadata": { "id": "bI5HUydhVj8z", "colab_type": "text" }, "source": [ "## Steps for calculating the part-time earnings.\n", "\n", "\n", "1. Importing the required (pandas) libraries.\n", "2. Storing values such as Date, Time Worked, and Money Earned in a DataFrame.\n", "3. Adding more rows to the existing DataFrame (updating the rows of the DataFrame).\n", "4. Calculating the sum of Money earned and the total duration worked.\n", "5. Plotting the bar graph with Date vs Money Earned.\n", "6. Including a search option inorder to search for the respective dates worked.\n", "7. Finally adding the payroll option.\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "5paGN0vYSlX1", "colab_type": "text" }, "source": [ "### Let’s get started !!!" ] }, { "cell_type": "markdown", "metadata": { "id": "FZpnQ4OKYIjP", "colab_type": "text" }, "source": [ " **1: Importing the required (pandas) libraries.**" ] }, { "cell_type": "markdown", "metadata": { "id": "_DSm4U9TYLTY", "colab_type": "text" }, "source": [ "In this tutorial we will only use the pandas library to perform the below calculations, the pandas library itself will provide us the option of calculating the sum and plotting a bar graph, you need not import matplotlib to plot a graph, pandas library will provide you the option of plotting a bar graph. This is would be very important to know to plot a bar graph using pandas DataFrame. You don’t have to install any pandas library if you are using Google Colab notebook then just import it. Otherwise, you have to manually install it in your command prompt by saying pip install pandas. The reason for aliasing (pd) is that I don’t have to write to pandas every single time when I want to use any methods by aliasing I can write pd.method name instead." ] }, { "cell_type": "code", "metadata": { "id": "I175AMSSYD62", "colab_type": "code", "colab": {} }, "source": [ "import pandas as pd" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "pWaqdQEtEYI3", "colab_type": "text" }, "source": [ "\n", "\n", "---\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "Nj7wzvLPAceT", "colab_type": "text" }, "source": [ "**2: Storing values such as Date, Time Worked, and Money Earned in a DataFrame.**" ] }, { "cell_type": "code", "metadata": { "id": "PJC8R7k_Aes5", "colab_type": "code", "outputId": "27c45776-0d35-4aa5-a276-f77a532ae951", "colab": { "base_uri": "https://localhost:8080/", "height": 202 } }, "source": [ "df = pd.DataFrame({'Date':['11/05/19', '12/05/19', '19/05/19', '25/05/19', '26/05/19', '1/06/19', '2/06/16', '6/06/19', '7/06/19', '8/06/19'],\n", " 'Time Worked': [3, 3, 4, 3, 3, 4, 4, 4, 3, 3],\n", " 'Money Earned': [33.94, 33.94, 46, 33.94, 33.94, 46, 46, 46, 33.94, 33.94]})\n", "df.head()" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "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", "
DateTime WorkedMoney Earned
011/05/19333.94
112/05/19333.94
219/05/19446.00
325/05/19333.94
426/05/19333.94
\n", "
" ], "text/plain": [ " Date Time Worked Money Earned\n", "0 11/05/19 3 33.94\n", "1 12/05/19 3 33.94\n", "2 19/05/19 4 46.00\n", "3 25/05/19 3 33.94\n", "4 26/05/19 3 33.94" ] }, "metadata": { "tags": [] }, "execution_count": 10 } ] }, { "cell_type": "markdown", "metadata": { "id": "kB4Cc8l5AflZ", "colab_type": "text" }, "source": [ "In this step I categorize all the data as Data, Time Worked and Money Earned into 3 columns. The Date column shows the date of the work in dd/mm/yy format and it will be stored as a String, the Time Worked shows the total amount of work done in a day (hours) stored as an integer, and the Money Earned showed the total money earned in a day (CAD dollar) it would be stored as an integer. Here for one hour, the minimum wage is 11.51 CAD. All these are just raw data, which is later stored in pandas DataFrame and allocated to a variable df. To do this just use “pd.DataFrame” and pass in all the data, by doing this the pandas will automatically convert the raw data into a DataFrame. I am using the head () because the data frame contains 10 rows of data so if I print them then they probably look big and cover most of the page, so instead the head() displays the top 5 data from the data frame.\n", "\n", "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "u3DpbBqREZgj", "colab_type": "text" }, "source": [ "\n", "\n", "---\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "FIIhmBPJEuTT", "colab_type": "text" }, "source": [ "**3: Adding more rows to the existing DataFrame (updating the rows of the DataFrame)**" ] }, { "cell_type": "markdown", "metadata": { "id": "4kvsPWSVFD0F", "colab_type": "text" }, "source": [ "In this step we will learn how to append or add more rows to the existing data frame, this is an important step because often many times you have to update your data frame by adding more rows, in this example I first create a new data frame called df2, and then call the append ( ) by passing the df2 as a parameter. You have to append the new data frame to the existing data frame like df.append(df2) (existing. append(new data frame)), now inside the append function we have some other parameters as ignore_index = True, this prevents the data frame from appending new index, so in this example all the index are in a continuous fashion (incrementing), and the next parameter is a sort = False this is because we don’t want to sort the data according to the index, otherwise our data would be completely a mixture, you can play with these parameters by changing the values as False and True respectively and note the difference. Last, the new appended data frame is stored into a new variable df." ] }, { "cell_type": "code", "metadata": { "id": "bzbtJAJAAmAj", "colab_type": "code", "outputId": "a6d81bc7-1458-4c94-ed61-ecef60610b86", "colab": { "base_uri": "https://localhost:8080/", "height": 141 } }, "source": [ "# Adding more rows\n", "df2 = pd.DataFrame({'Date': ['10/06/19', '12/06/19', '14/06/19'],\n", " 'Time Worked': [3, 4, 3],\n", " 'Money Earned': [33.94, 46, 33.94]})\n", "df2" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "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", "
DateTime WorkedMoney Earned
010/06/19333.94
112/06/19446.00
214/06/19333.94
\n", "
" ], "text/plain": [ " Date Time Worked Money Earned\n", "0 10/06/19 3 33.94\n", "1 12/06/19 4 46.00\n", "2 14/06/19 3 33.94" ] }, "metadata": { "tags": [] }, "execution_count": 8 } ] }, { "cell_type": "code", "metadata": { "id": "xYhG1MyAFeIj", "colab_type": "code", "outputId": "ff6f3bfb-201e-41de-941d-5ab56784ee66", "colab": { "base_uri": "https://localhost:8080/", "height": 202 } }, "source": [ "df = df.append(df2, ignore_index=True, sort = False)\n", "df.head()" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "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", "
DateTime WorkedMoney Earned
011/05/19333.94
112/05/19333.94
219/05/19446.00
325/05/19333.94
426/05/19333.94
\n", "
" ], "text/plain": [ " Date Time Worked Money Earned\n", "0 11/05/19 3 33.94\n", "1 12/05/19 3 33.94\n", "2 19/05/19 4 46.00\n", "3 25/05/19 3 33.94\n", "4 26/05/19 3 33.94" ] }, "metadata": { "tags": [] }, "execution_count": 11 } ] }, { "cell_type": "markdown", "metadata": { "id": "Vxq287deKtqu", "colab_type": "text" }, "source": [ "\n", "\n", "---\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "LlcPTAIOJAva", "colab_type": "text" }, "source": [ "**4. Calculating the sum of Money earned and the total duration worked**" ] }, { "cell_type": "markdown", "metadata": { "id": "74sKj0BJJw9_", "colab_type": "text" }, "source": [ "This step is pretty much straightforward because we are just getting the sum of the “Money Earned” and “Time Worked” columns to do this all you have to do is just use the sum () which will return the sum of all the data from the columns. I’m just using the round () for the Total_earnings just to get the precise values. Make sure you pass the correct column name inside df, because if the column names mismatch then it can put you in trouble. Finally, I print the results in a more readable way." ] }, { "cell_type": "code", "metadata": { "id": "zt-kl3TpI8Gd", "colab_type": "code", "outputId": "3f88dabb-65f5-4d47-ad16-909817a00f40", "colab": { "base_uri": "https://localhost:8080/", "height": 69 } }, "source": [ "Total_earnings = df['Money Earned'].sum()\n", "Total_time = df['Time Worked'].sum()\n", "\n", "print(\"You have earned total of ====>\" ,round(Total_earnings), \"CAD\")\n", "print(\"---------------------------------------------------------------\")\n", "print(\"You have worked for total of ====>\", Total_time, \"hours\")" ], "execution_count": 0, "outputs": [ { "output_type": "stream", "text": [ "You have earned total of ====> 502.0 CAD\n", "---------------------------------------------------------------\n", "You have worked for total of ====> 44 hours\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "f6tz8Tv4KuaH", "colab_type": "text" }, "source": [ "\n", "\n", "---\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "ymF-0xugK2l1", "colab_type": "text" }, "source": [ "**5. Plotting the bar graph with Total duration vs Money Earned**" ] }, { "cell_type": "markdown", "metadata": { "id": "gOrlJYXXM8gX", "colab_type": "text" }, "source": [ "As I mentioned earlier, to plot a graph, you don’t have to import matplot library, pandas have a plot () which will help you plot a graph up to a certain extent. I have used the plot () and passed the “Date” and the “Money Earned” as x and y values (because you need x and y values to plot a graph ;) and I want a bar graph so I used the kind as bar, you can also use line, scatter to the keyword kind. We then get a beautiful bar graph with all the values plotted according to our expectations." ] }, { "cell_type": "code", "metadata": { "id": "N4dbwFWnK3lg", "colab_type": "code", "outputId": "1fd5c1ef-550d-49c5-dc33-144a5c1fc1e7", "colab": { "base_uri": "https://localhost:8080/", "height": 336 } }, "source": [ "df.plot(x ='Date', y='Money Earned', kind = 'bar')" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "" ] }, "metadata": { "tags": [] }, "execution_count": 17 }, { "output_type": "display_data", "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEtCAYAAAAY4ptsAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAH+lJREFUeJzt3Xm4XFWd7vHvSxKSkAAZCDQmwoGG\nQPASgwYC3dLGoMwirRDAIYHIRVsRQbyKdtsBLzJ026Je4FFAIMo8KCggiEjwSZBAAiECQUBkODRC\nDIRBEjvD7/6x9kkqh3M4066dqsX7eZ56UrV3nf1bqyr11q5Vu9ZWRGBmZs1vow3dADMzK4cD3cws\nEw50M7NMONDNzDLhQDczy4QD3cwsEw50M7NMONDNzDLhQDczy0T/KottscUW0dLSUmVJM7Omt2DB\ngr9ExKiu7ldpoLe0tDB//vwqS5qZNT1JT3fnfh5yMTPLhAPdzCwTDnQzs0xUOoZuZtVbuXIlra2t\nrFixYkM3xbowaNAgxowZw4ABA3r19w50s8y1tray6aab0tLSgqQN3RzrRESwdOlSWltb2W677Xq1\nD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] }, { "cell_type": "markdown", "metadata": { "id": "fmLGB2ASO6WR", "colab_type": "text" }, "source": [ "Shown above is not the best way to plot a graph, but I have shown you guys that pandas library can help you plot a graph, sometimes it’s handy to use this method where there would be fewer data and fewer calculations all you have to do is plot a graph with x and y values.\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "vM7ZejKHSC40", "colab_type": "text" }, "source": [ "\n", "\n", "---\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "QJVyOgTJPoUS", "colab_type": "text" }, "source": [ "**6. Including a search option in order to search for the respective dates worked.**" ] }, { "cell_type": "markdown", "metadata": { "id": "OQBRP7r1QDCj", "colab_type": "text" }, "source": [ "This is an additional step, just to give it a feel like a database I threw in a few features, such as a search option. In real time projects, this is a handy feature where you often have to search for the data, there you cannot search it manually, so with the help of this below code snippet you just get the job done. In this example I have used the str.contains ( ) for the search operation and passed the data as a parameter, now the data is a variable which contains the user entered data to be searched. When you type in the date the str.contains() searches for the entered date and them displays the date and the corresponding values from the data frame. This would be helpful when you want to search for a particular data and the get the time and money earned, you can just type in the date and get the results quick rather than manually finding the required date.\n", "\n" ] }, { "cell_type": "code", "metadata": { "id": "TX2EhMQkK_Wb", "colab_type": "code", "outputId": "2b8e65ff-5340-4e40-a109-1ccf3fba1f5e", "colab": { "base_uri": "https://localhost:8080/", "height": 97 } }, "source": [ "date = input(\"Enter the date you want to search ===> \")\n", "df[df['Date'].str.contains(date)]" ], "execution_count": 0, "outputs": [ { "output_type": "stream", "text": [ "Enter the date you want to search ===> 26/05/19\n" ], "name": "stdout" }, { "output_type": "execute_result", "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
DateTime WorkedMoney Earned
426/05/19333.94
\n", "
" ], "text/plain": [ " Date Time Worked Money Earned\n", "4 26/05/19 3 33.94" ] }, "metadata": { "tags": [] }, "execution_count": 21 } ] }, { "cell_type": "markdown", "metadata": { "id": "kYCCLCsPSEDt", "colab_type": "text" }, "source": [ "\n", "\n", "---\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "odA6cONXSErm", "colab_type": "text" }, "source": [ "**7. Finally adding the payroll option**" ] }, { "cell_type": "markdown", "metadata": { "id": "7njtuyOdSM6u", "colab_type": "text" }, "source": [ "This is more like an optional (bonus) step because this generates payroll for the entered data, this is not an industry level payroll generator, rather a simple payroll generator with a different function and print statements. The logic is very simple to understand all I have done is taken the name, hours and rate as user inputs and then multiplied the rate and hours and stored them in the total_money and enclosed it in a function.\n", "\n", "\n", "\n" ] }, { "cell_type": "code", "metadata": { "id": "7AUEBUXqSO2U", "colab_type": "code", "colab": {} }, "source": [ "def payroll():\n", " name = input(\"Enter the name of the employee: ==> \")\n", " hours = int(input(\"Enter the number of hours worked by the employeer ==> \"))\n", " rate = float(input(\"Enter the pay rate for one hour ==> \"))\n", " \n", " total_money = hours * rate \n", " print(\"The total money earned by \", name, \"for working \", hours, \"hours\", \"is ===> \", round(total_money), \"CAD\")" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "mRu3delXTY73", "colab_type": "code", "outputId": "e49a3484-bb38-4cfb-e495-f19ab9f32efc", "colab": { "base_uri": "https://localhost:8080/", "height": 87 } }, "source": [ "payroll()" ], "execution_count": 0, "outputs": [ { "output_type": "stream", "text": [ "Enter the name of the employee: ==> Tanu N Prabhu\n", "Enter the number of hours worked by the employeer ==> 44\n", "Enter the pay rate for one hour ==> 11.51\n", "The total money earned by Tanu N Prabhu for working 44 hours is ===> 506 CAD\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "s7DWEqBmUBDt", "colab_type": "text" }, "source": [ "\n", "\n", "---\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "djsH6ZeuUhEe", "colab_type": "text" }, "source": [ "Hence this is how you can calculate the part-time earnings using a pandas data frame with a python. I know this is easy to understand because I have given as much as an explanation of the code I could and the rest you can practice on your own. This is a good start if you know little about pandas library, these are some basic methods that should be at your fingertips. I’m going to stop here and let you practice the code. If you have any doubts, let me know in the comments section, or drop a mail to tanunprabhu95@gmail.com just let me know your issue and I will definitely solve your problem. Moreover I am an author in [towardsdatascience.com](https://medium.com/@tanunprabhu95) and you can find this [article](https://medium.com/@tanunprabhu95/manipulating-the-data-with-pandas-using-python-be6c5dfabd47) there. Have a nice day. See you have a good day !!!!.\n" ] }, { "cell_type": "markdown", "metadata": { "id": "EP2-3iSqVyfF", "colab_type": "text" }, "source": [ "# Thankyou\n", "\n", "## Author\n", "## Tanu Nanda Prabhu" ] }, { "cell_type": "markdown", "metadata": { "id": "Xg784mIzV889", "colab_type": "text" }, "source": [ "\n", "\n", "---\n", "\n" ] } ] }