SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.  "cells": [
  3.   {
  4.    "cell_type": "code",
  5.    "execution_count": 2,
  6.    "metadata": {},
  7.    "outputs": [
  8.     {
  9.      "data": {
  10.       "text/html": [
  11.        "<div>\n",
  12.        "<style scoped>\n",
  13.        "    .dataframe tbody tr th:only-of-type {\n",
  14.        "        vertical-align: middle;\n",
  15.        "    }\n",
  16.        "\n",
  17.        "    .dataframe tbody tr th {\n",
  18.        "        vertical-align: top;\n",
  19.        "    }\n",
  20.        "\n",
  21.        "    .dataframe thead th {\n",
  22.        "        text-align: right;\n",
  23.        "    }\n",
  24.        "</style>\n",
  25.        "<table border=\"1\" class=\"dataframe\">\n",
  26.        "  <thead>\n",
  27.        "    <tr style=\"text-align: right;\">\n",
  28.        "      <th></th>\n",
  29.        "      <th>price</th>\n",
  30.        "      <th>price_binned</th>\n",
  31.        "    </tr>\n",
  32.        "  </thead>\n",
  33.        "  <tbody>\n",
  34.        "    <tr>\n",
  35.        "      <th>0</th>\n",
  36.        "      <td>13495</td>\n",
  37.        "      <td>Low</td>\n",
  38.        "    </tr>\n",
  39.        "    <tr>\n",
  40.        "      <th>1</th>\n",
  41.        "      <td>16500</td>\n",
  42.        "      <td>Medium</td>\n",
  43.        "    </tr>\n",
  44.        "    <tr>\n",
  45.        "      <th>2</th>\n",
  46.        "      <td>18920</td>\n",
  47.        "      <td>Medium</td>\n",
  48.        "    </tr>\n",
  49.        "    <tr>\n",
  50.        "      <th>3</th>\n",
  51.        "      <td>41315</td>\n",
  52.        "      <td>very high</td>\n",
  53.        "    </tr>\n",
  54.        "    <tr>\n",
  55.        "      <th>4</th>\n",
  56.        "      <td>5151</td>\n",
  57.        "      <td>very low</td>\n",
  58.        "    </tr>\n",
  59.        "    <tr>\n",
  60.        "      <th>5</th>\n",
  61.        "      <td>6295</td>\n",
  62.        "      <td>Low</td>\n",
  63.        "    </tr>\n",
  64.        "  </tbody>\n",
  65.        "</table>\n",
  66.        "</div>"
  67.       ],
  68.       "text/plain": [
  69.        "   price price_binned\n",
  70.        "0  13495          Low\n",
  71.        "1  16500       Medium\n",
  72.        "2  18920       Medium\n",
  73.        "3  41315    very high\n",
  74.        "4   5151     very low\n",
  75.        "5   6295          Low"
  76.       ]
  77.      },
  78.      "execution_count": 2,
  79.      "metadata": {},
  80.      "output_type": "execute_result"
  81.     }
  82.    ],
  83.    "source": [
  84.     "import pandas as pd\n",
  85.     "list = {'price':[13495, 16500, 18920, 41315, 5151, 6295]}\n",
  86.     "df = pd.DataFrame(list)\n",
  87.     "bandwidth = int((max(df['price']) - min(df['price']))/4)\n",
  88.     "bins = range(min(df['price'])-bandwidth, max(df['price'])+bandwidth, bandwidth)\n",
  89.     "group_names = ['very low','Low', 'Medium', 'High', 'very high']\n",
  90.     "df['price_binned'] = pd.cut(df['price'], bins, labels = group_names)\n",
  91.     "df"
  92.    ]
  93.   }
  94.  ],
  95.  "metadata": {
  96.   "kernelspec": {
  97.    "display_name": "Python 3",
  98.    "language": "python",
  99.    "name": "python3"
  100.   },
  101.   "language_info": {
  102.    "codemirror_mode": {
  103.     "name": "ipython",
  104.     "version": 3
  105.    },
  106.    "file_extension": ".py",
  107.    "mimetype": "text/x-python",
  108.    "name": "python",
  109.    "nbconvert_exporter": "python",
  110.    "pygments_lexer": "ipython3",
  111.    "version": "3.6.7"
  112.   }
  113.  },
  114.  "nbformat": 4,
  115.  "nbformat_minor": 4
  116. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top