{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from scipy import stats\n", "import numpy as np\n", "from sklearn.feature_extraction.text import CountVectorizer\n", "from sklearn.feature_extraction.text import TfidfTransformer\n", "import glob\n", "from functools import partial\n", "from decimal import *\n", "\n", "\n", "data='./3classdata/W/1.csv'\n", "#data='./progetto/3classdata/Y/2.csv'\n", "window=3\n", "resolution=500\n", "shift=3\n" ] }, { "cell_type": "raw", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def round(n):\n", " pst = '0.00001'\n", " precision = Decimal(pst)\n", " getcontext().prec = len(pst)\n", " return Decimal(n).quantize(precision)\n", "assert round(5.00000000000000001)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-1. , -0.48715223, -0.40806948, -0.3564728 , -0.31673373,\n", " -0.28370106, -0.25499594, -0.22931092, -0.20584419, -0.18406497,\n", " -0.16360107, -0.14417942, -0.1255919 , -0.10767457, -0.09029443,\n", " -0.07334053, -0.05671771, -0.04034218, -0.02413812, -0.00803494,\n", " 0.00803494, 0.02413812, 0.04034218, 0.05671771, 0.07334053,\n", " 0.09029443, 0.10767457, 0.1255919 , 0.14417942, 0.16360107,\n", " 0.18406497, 0.20584419, 0.22931092, 0.25499594, 0.28370106,\n", " 0.31673373, 0.3564728 , 0.40806948, 0.48715223, 1. ])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def gaussian_interval(resolution):\n", " # use a gaussian distribution, mean 0, std deviation 0.25\n", " distribution = stats.norm(loc=0, scale=0.25)\n", " # bounds of range for inverse comulative distribution function\n", " bounds = distribution.cdf([-1, 1])\n", " # generate linear space of 2*resolution points using bounds\n", " linsp = np.linspace(*bounds, num=2*resolution)\n", " # obtain the array of 2*resolution points\n", " return distribution.ppf(linsp)\n", "gaussian_interval(20)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(data, dtype=float, header=None)\n", "# rotate dataframe (each column is a temporal sequence)\n", "df = df.T.reset_index().reindex(axis=1).drop(['index'], axis=1).infer_objects()\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "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", " \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", " \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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012345678910111213141516171819
0-0.794245-1.0000000.828071-0.9941680.9447980.668407-0.373019-0.1506700.8471870.9930110.9976490.4248280.707602-0.548011-0.897720-0.9961910.7333331.000000-1.000000-1.000000
1-0.773646-0.9820510.838096-1.0000000.7027600.490809-0.5362550.5223350.9496221.0000001.0000000.4167610.719298-0.696552-0.840543-1.0000000.7212120.707079-0.989454-0.998286
2-0.704494-0.9417070.867532-0.9715830.5159240.189991-0.6675240.5570230.9462640.9405910.540661-0.1312390.754386-0.875862-0.722166-0.9907370.7151520.664768-0.700204-0.977304
3-0.702488-0.7276780.847612-0.9567490.222930-0.078956-0.7595380.5732420.9143580.871396-0.152875-0.2462310.766082-0.839788-0.739604-0.9377560.6606060.243287-0.358765-0.947124
4-0.653693-0.4749160.893637-0.896301-0.210191-0.359162-0.840516-1.0000000.9932830.808842-0.618419-0.5358110.812865-0.818568-0.519115-0.8232840.6303030.222132-0.169913-0.810559
\n", "
" ], "text/plain": [ " 0 1 2 3 4 5 6 \\\n", "0 -0.794245 -1.000000 0.828071 -0.994168 0.944798 0.668407 -0.373019 \n", "1 -0.773646 -0.982051 0.838096 -1.000000 0.702760 0.490809 -0.536255 \n", "2 -0.704494 -0.941707 0.867532 -0.971583 0.515924 0.189991 -0.667524 \n", "3 -0.702488 -0.727678 0.847612 -0.956749 0.222930 -0.078956 -0.759538 \n", "4 -0.653693 -0.474916 0.893637 -0.896301 -0.210191 -0.359162 -0.840516 \n", "\n", " 7 8 9 10 11 12 13 \\\n", "0 -0.150670 0.847187 0.993011 0.997649 0.424828 0.707602 -0.548011 \n", "1 0.522335 0.949622 1.000000 1.000000 0.416761 0.719298 -0.696552 \n", "2 0.557023 0.946264 0.940591 0.540661 -0.131239 0.754386 -0.875862 \n", "3 0.573242 0.914358 0.871396 -0.152875 -0.246231 0.766082 -0.839788 \n", "4 -1.000000 0.993283 0.808842 -0.618419 -0.535811 0.812865 -0.818568 \n", "\n", " 14 15 16 17 18 19 \n", "0 -0.897720 -0.996191 0.733333 1.000000 -1.000000 -1.000000 \n", "1 -0.840543 -1.000000 0.721212 0.707079 -0.989454 -0.998286 \n", "2 -0.722166 -0.990737 0.715152 0.664768 -0.700204 -0.977304 \n", "3 -0.739604 -0.937756 0.660606 0.243287 -0.358765 -0.947124 \n", "4 -0.519115 -0.823284 0.630303 0.222132 -0.169913 -0.810559 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = ((df - df.min()) / (df.max() - df.min()))*2 - 1\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "scrolled": true }, "outputs": [], "source": [ "#df = df.apply(partial(\n", " # discretize_series, gaussianInterval=gaussian_interval(resolution)))\n", "#df.head()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "l = df.apply(lambda x : pd.cut(x, gaussian_interval(resolution), right=True).apply(lambda l : l.left))\n", "r = df.apply(lambda x : pd.cut(x, gaussian_interval(resolution), right=True).apply(lambda l : l.right))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "df = l" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "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", " \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", " \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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012345678910111213141516171819
0-1.0000-1.00000.7702-1.00.77020.66230-0.3744-0.15070.77020.77020.77020.42370.6860-0.5490-1.0000-1.00.71820.7702-1.0000-1.0
1-1.0000-1.00000.7702-1.00.68600.48980-0.54220.51840.77020.77020.77020.41590.7182-0.7182-1.0000-1.00.71820.6860-1.0000-1.0
2-0.7182-1.00000.7702-1.00.51320.18950-0.68600.55620.77020.77020.5358-0.13160.7182-1.0000-0.7702-1.00.68600.6623-0.7182-1.0
3-0.7182-0.77020.7702-1.00.2221-0.07941-0.77020.57220.77020.7702-0.1530-0.24640.7182-1.0000-0.7702-1.00.64330.2423-0.3597-1.0
4-0.6623-0.47750.7702-1.0-0.2102-0.35970-1.0000-1.00000.77020.7702-0.6275-0.53580.7702-1.0000-0.5240-1.00.62750.2221-0.1700-1.0
\n", "
" ], "text/plain": [ " 0 1 2 3 4 5 6 7 8 \\\n", "0 -1.0000 -1.0000 0.7702 -1.0 0.7702 0.66230 -0.3744 -0.1507 0.7702 \n", "1 -1.0000 -1.0000 0.7702 -1.0 0.6860 0.48980 -0.5422 0.5184 0.7702 \n", "2 -0.7182 -1.0000 0.7702 -1.0 0.5132 0.18950 -0.6860 0.5562 0.7702 \n", "3 -0.7182 -0.7702 0.7702 -1.0 0.2221 -0.07941 -0.7702 0.5722 0.7702 \n", "4 -0.6623 -0.4775 0.7702 -1.0 -0.2102 -0.35970 -1.0000 -1.0000 0.7702 \n", "\n", " 9 10 11 12 13 14 15 16 17 \\\n", "0 0.7702 0.7702 0.4237 0.6860 -0.5490 -1.0000 -1.0 0.7182 0.7702 \n", "1 0.7702 0.7702 0.4159 0.7182 -0.7182 -1.0000 -1.0 0.7182 0.6860 \n", "2 0.7702 0.5358 -0.1316 0.7182 -1.0000 -0.7702 -1.0 0.6860 0.6623 \n", "3 0.7702 -0.1530 -0.2464 0.7182 -1.0000 -0.7702 -1.0 0.6433 0.2423 \n", "4 0.7702 -0.6275 -0.5358 0.7702 -1.0000 -0.5240 -1.0 0.6275 0.2221 \n", "\n", " 18 19 \n", "0 -1.0000 -1.0 \n", "1 -1.0000 -1.0 \n", "2 -0.7182 -1.0 \n", "3 -0.3597 -1.0 \n", "4 -0.1700 -1.0 " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ " #df = df.round(5).astype(Decimal)\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "def generate_words(col, w, s):\n", " word = []\n", " idx = 0\n", " distance = abs(w-s)\n", " while idx < len(col):\n", " if len(word) == w:\n", " yield tuple(word)\n", " word = []\n", " if w < s and idx == w:\n", " idx += distance\n", " if w > s:\n", " idx -= distance \n", " else:\n", " word.append(round(col[idx]))\n", " idx+=1" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "scrolled": true }, "outputs": [], "source": [ "def rolling_window(df, w, s):\n", " ret = list()\n", " for _,col in df.iteritems():\n", " ret.append(tuple(generate_words(col, w, s)))\n", " return pd.DataFrame(ret).T.reset_index().reindex(axis=1).drop(['index'], axis=1)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0 \\\n", "0 (-1.00000, -1.00000, -0.71820, -0.71820, -0.66... \n", "1 (-0.71820, -0.66230, -0.28860, -0.12660, 0.16140) \n", "2 (-0.12660, 0.16140, 0.49410, 0.50810, 0.60180) \n", "3 (0.50810, 0.60180, 0.66230, 0.77020, 0.77020) \n", "4 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "5 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "6 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "7 (0.77020, 0.77020, 0.77020, 0.77020, 0.66230) \n", "8 (0.77020, 0.66230, 0.26220, 0.24640, -0.22390) \n", "9 (0.24640, -0.22390, -0.34940, -0.77020, -1.00000) \n", "10 (-0.77020, -1.00000, -1.00000, -1.00000, -1.00... \n", "11 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "\n", " 1 \\\n", "0 (-1.00000, -1.00000, -1.00000, -0.77020, -0.47... \n", "1 (-0.77020, -0.47750, -0.71820, -0.37440, -0.04... \n", "2 (-0.37440, -0.04573, 0.24950, 0.54220, 0.44340) \n", "3 (0.54220, 0.44340, 0.37830, 0.66230, 0.77020) \n", "4 (0.66230, 0.77020, 0.77020, 0.77020, 0.77020) \n", "5 (0.77020, 0.77020, 0.71820, 0.62750, 0.52400) \n", "6 (0.62750, 0.52400, 0.44040, 0.57220, 0.64330) \n", "7 (0.57220, 0.64330, 0.71820, 0.71820, 0.77020) \n", "8 (0.71820, 0.77020, 0.77020, 0.77020, 0.66230) \n", "9 (0.77020, 0.66230, 0.56390, 0.33660, 0.36150) \n", "10 (0.33660, 0.36150, 0.20750, 0.08073, 0.09947) \n", "11 (0.08073, 0.09947, -0.25360, -0.21200, -0.29360) \n", "\n", " 2 \\\n", "0 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "1 (0.77020, 0.77020, 0.77020, 0.77020, 0.66230) \n", "2 (0.77020, 0.66230, 0.38640, 0.17960, 0.00157) \n", "3 (0.17960, 0.00157, -0.19880, -0.40860, -0.29480) \n", "4 (-0.40860, -0.29480, -0.22580, -0.61380, -1.00... \n", "5 (-0.61380, -1.00000, -1.00000, -1.00000, -1.00... \n", "6 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "7 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "8 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "9 (-1.00000, -1.00000, -0.71820, -0.64330, -0.45... \n", "10 (-0.64330, -0.45940, -0.38640, -0.17080, -0.00... \n", "11 (-0.17080, -0.00721, 0.12020, 0.29360, 0.31740) \n", "\n", " 3 \\\n", "0 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "1 (-1.00000, -1.00000, -0.77020, -1.00000, -0.77... \n", "2 (-1.00000, -0.77020, -0.62750, -0.27560, -0.27... \n", "3 (-0.27560, -0.27910, -0.02671, 0.17800, 0.52970) \n", "4 (0.17800, 0.52970, 0.77020, 0.77020, 0.77020) \n", "5 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "6 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "7 (0.77020, 0.77020, 0.45940, 0.44640, 0.27790) \n", "8 (0.44640, 0.27790, 0.12230, -0.09138, -0.14330) \n", "9 (-0.09138, -0.14330, -0.26110, -0.29480, -0.31... \n", "10 (-0.29480, -0.31880, -0.37060, -0.37640, -0.38... \n", "11 (-0.37640, -0.38030, -0.38030, -0.38030, -0.39... \n", "\n", " 4 \\\n", "0 (0.77020, 0.68600, 0.51320, 0.22210, -0.21020) \n", "1 (0.22210, -0.21020, -0.01098, 0.18040, 0.30250) \n", "2 (0.18040, 0.30250, -0.03619, -0.51320, -0.49410) \n", "3 (-0.51320, -0.49410, -0.51840, -0.32600, 0.23540) \n", "4 (-0.32600, 0.23540, 0.60180, 0.71820, 0.77020) \n", "5 (0.71820, 0.77020, 0.77020, 0.77020, 0.35450) \n", "6 (0.77020, 0.35450, 0.00157, -0.20230, -0.24030) \n", "7 (-0.20230, -0.24030, -0.18120, 0.00157, 0.24740) \n", "8 (0.00157, 0.24740, 0.37440, 0.48560, 0.41590) \n", "9 (0.48560, 0.41590, 0.27790, -0.04892, -0.20230) \n", "10 (-0.04892, -0.20230, -0.54220, -0.59100, -0.71... \n", "11 (-0.59100, -0.71820, -1.00000, -1.00000, -1.00... \n", "\n", " 5 \\\n", "0 (0.66230, 0.48980, 0.18950, -0.07941, -0.35970) \n", "1 (-0.07941, -0.35970, -0.44960, -0.60180, -0.71... \n", "2 (-0.60180, -0.71820, -0.77020, -1.00000, -1.00... \n", "3 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "4 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "5 (-1.00000, -1.00000, -1.00000, -0.66230, -0.47... \n", "6 (-0.66230, -0.47750, -0.24130, -0.08404, 0.21290) \n", "7 (-0.08404, 0.21290, 0.31880, 0.48560, 0.61380) \n", "8 (0.48560, 0.61380, 0.71820, 0.77020, 0.77020) \n", "9 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "10 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "11 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "\n", " 6 \\\n", "0 (-0.37440, -0.54220, -0.68600, -0.77020, -1.00... \n", "1 (-0.77020, -1.00000, -1.00000, -1.00000, -1.00... \n", "2 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "3 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "4 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "5 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "6 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "7 (-1.00000, -1.00000, -1.00000, -0.34290, 0.19200) \n", "8 (-0.34290, 0.19200, 0.47000, 0.71820, 0.77020) \n", "9 (0.71820, 0.77020, 0.77020, 0.77020, 0.77020) \n", "10 (0.77020, 0.77020, 0.77020, 0.55620, 0.05598) \n", "11 (0.55620, 0.05598, -0.44340, -0.44960, -0.64330) \n", "\n", " 7 \\\n", "0 (-0.15070, 0.51840, 0.55620, 0.57220, -1.00000) \n", "1 (0.57220, -1.00000, 0.68600, 0.03936, -0.09406) \n", "2 (0.03936, -0.09406, 0.11460, 0.45600, 0.71820) \n", "3 (0.45600, 0.71820, 0.77020, 0.64330, 0.39710) \n", "4 (0.64330, 0.39710, 0.30120, 0.27910, 0.39060) \n", "5 (0.27910, 0.39060, 0.61380, 0.77020, 0.77020) \n", "6 (0.77020, 0.77020, 0.77020, 0.77020, 0.71820) \n", "7 (0.77020, 0.71820, 0.64330, 0.50330, 0.45280) \n", "8 (0.50330, 0.45280, 0.43750, 0.41590, 0.37640) \n", "9 (0.41590, 0.37640, 0.36880, 0.33350, 0.33500) \n", "10 (0.33350, 0.33500, 0.33660, 0.30910, 0.27440) \n", "11 (0.30910, 0.27440, 0.27330, 0.26430, 0.24740) \n", "\n", " 8 \\\n", "0 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "1 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "2 (0.77020, 0.77020, 0.77020, 0.77020, 0.71820) \n", "3 (0.77020, 0.71820, 0.56390, 0.07415, 0.27220) \n", "4 (0.07415, 0.27220, -0.20750, -0.51840, -0.34130) \n", "5 (-0.51840, -0.34130, -0.57220, -0.71820, -0.68... \n", "6 (-0.71820, -0.68600, -0.66230, -0.71820, -0.77... \n", "7 (-0.71820, -0.77020, -1.00000, -1.00000, -1.00... \n", "8 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "9 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "10 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "11 (-1.00000, -1.00000, -0.77020, -0.77020, -0.77... \n", "\n", " 9 \\\n", "0 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "1 (0.77020, 0.77020, 0.71820, 0.60180, 0.64330) \n", "2 (0.60180, 0.64330, 0.66230, 0.64330, 0.52400) \n", "3 (0.64330, 0.52400, 0.32600, -0.25260, -0.71820) \n", "4 (-0.25260, -0.71820, -1.00000, -1.00000, -1.00... \n", "5 (-1.00000, -1.00000, -0.71820, -0.36330, -0.39... \n", "6 (-0.36330, -0.39710, -0.32020, -0.27790, -0.27... \n", "7 (-0.27790, -0.27440, -0.25890, -0.26540, -0.27... \n", "8 (-0.26540, -0.27220, -0.27910, -0.27790, -0.24... \n", "9 (-0.27790, -0.24950, -0.27670, -0.28140, -0.25... \n", "10 (-0.28140, -0.25570, -0.17480, -0.05662, 0.01915) \n", "11 (-0.05662, 0.01915, 0.08404, 0.11600, 0.14620) \n", "\n", " 10 \\\n", "0 (0.77020, 0.77020, 0.53580, -0.15300, -0.62750) \n", "1 (-0.15300, -0.62750, -0.71820, -1.00000, -1.00... \n", "2 (-1.00000, -1.00000, -0.62750, -0.10080, 0.11880) \n", "3 (-0.10080, 0.11880, 0.39490, 0.21650, 0.02860) \n", "4 (0.21650, 0.02860, 0.38440, 0.56390, 0.62750) \n", "5 (0.56390, 0.62750, 0.71820, 0.77020, 0.77020) \n", "6 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "7 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "8 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "9 (0.77020, 0.77020, 0.44960, -0.15220, -0.47750) \n", "10 (-0.15220, -0.47750, -0.15530, 0.18620, 0.39490) \n", "11 (0.18620, 0.39490, 0.44960, 0.46640, 0.51840) \n", "\n", " 11 \\\n", "0 (0.42370, 0.41590, -0.13160, -0.24640, -0.53580) \n", "1 (-0.24640, -0.53580, -0.50330, -1.00000, -1.00... \n", "2 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "3 (-1.00000, -1.00000, -0.68600, -1.00000, -0.66... \n", "4 (-1.00000, -0.66230, -0.57220, -0.49410, -0.39... \n", "5 (-0.49410, -0.39940, -0.46280, -0.42370, -0.31... \n", "6 (-0.42370, -0.31050, -0.39710, -0.41850, -0.44... \n", "7 (-0.41850, -0.44040, -0.47000, -0.40860, 0.09541) \n", "8 (-0.40860, 0.09541, 0.30120, 0.77020, 0.77020) \n", "9 (0.77020, 0.77020, 0.77020, 0.77020, 0.71820) \n", "10 (0.77020, 0.71820, 0.42630, 0.48560, 0.54220) \n", "11 (0.48560, 0.54220, 0.50330, 0.46280, 0.45940) \n", "\n", " 12 \\\n", "0 (0.68600, 0.71820, 0.71820, 0.71820, 0.77020) \n", "1 (0.71820, 0.77020, 0.77020, 0.77020, 0.77020) \n", "2 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "3 (0.77020, 0.77020, 0.77020, 0.77020, 0.71820) \n", "4 (0.77020, 0.71820, 0.56390, 0.21560, 0.15760) \n", "5 (0.21560, 0.15760, 0.13450, -0.33350, -0.61380) \n", "6 (-0.33350, -0.61380, -0.55620, -0.55620, -0.53... \n", "7 (-0.55620, -0.53580, -0.46280, -0.44040, -0.41... \n", "8 (-0.44040, -0.41590, -0.42900, -0.39280, -0.44... \n", "9 (-0.39280, -0.44040, -0.51320, -0.57220, -0.71... \n", "10 (-0.57220, -0.71820, -1.00000, -1.00000, -1.00... \n", "11 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "\n", " 13 \\\n", "0 (-0.54900, -0.71820, -1.00000, -1.00000, -1.00... \n", "1 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "2 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "3 (-1.00000, -1.00000, -1.00000, -0.38230, -0.19... \n", "4 (-0.38230, -0.19620, 0.06827, 0.47000, 0.77020) \n", "5 (0.47000, 0.77020, 0.77020, 0.77020, 0.77020) \n", "6 (0.77020, 0.77020, 0.77020, 0.77020, 0.51320) \n", "7 (0.77020, 0.51320, 0.21560, 0.28140, 0.28860) \n", "8 (0.28140, 0.28860, 0.27100, 0.25150, 0.21650) \n", "9 (0.25150, 0.21650, 0.13590, 0.15910, -0.07284) \n", "10 (0.15910, -0.07284, -0.02104, 0.00533, 0.04064) \n", "11 (0.00533, 0.04064, 0.06502, 0.12730, -0.03239) \n", "\n", " 14 \\\n", "0 (-1.00000, -1.00000, -0.77020, -0.77020, -0.52... \n", "1 (-0.77020, -0.52400, -0.27670, 0.07677, 0.48980) \n", "2 (0.07677, 0.48980, 0.77020, 0.77020, 0.77020) \n", "3 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "4 (0.77020, 0.77020, 0.77020, 0.77020, 0.71820) \n", "5 (0.77020, 0.71820, 0.68600, 0.58120, 0.57220) \n", "6 (0.58120, 0.57220, 0.51840, 0.52400, 0.51840) \n", "7 (0.52400, 0.51840, 0.52970, 0.52970, 0.54900) \n", "8 (0.52970, 0.54900, 0.55620, 0.57220, 0.56390) \n", "9 (0.57220, 0.56390, 0.55620, 0.51320, 0.43750) \n", "10 (0.51320, 0.43750, 0.30250, 0.29230, 0.07349) \n", "11 (0.29230, 0.07349, -0.21740, -0.50810, -1.00000) \n", "\n", " 15 \\\n", "0 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "1 (-1.00000, -1.00000, -0.71820, -0.64330, -0.51... \n", "2 (-0.64330, -0.51840, -0.41350, -0.35110, -0.26... \n", "3 (-0.35110, -0.26110, -0.15070, 0.15530, 0.34130) \n", "4 (0.15530, 0.34130, 0.77020, 0.51840, 0.71820) \n", "5 (0.51840, 0.71820, 0.77020, 0.77020, 0.77020) \n", "6 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "7 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "8 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "9 (0.77020, 0.77020, 0.44040, 0.51840, 0.46640) \n", "10 (0.51840, 0.46640, 0.39280, 0.30780, 0.25790) \n", "11 (0.30780, 0.25790, 0.14180, 0.07809, 0.04701) \n", "\n", " 16 \\\n", "0 (0.71820, 0.71820, 0.68600, 0.64330, 0.62750) \n", "1 (0.64330, 0.62750, 0.62750, 0.04191, -0.30380) \n", "2 (0.04191, -0.30380, -0.64330, -0.77020, -1.00000) \n", "3 (-0.77020, -1.00000, -1.00000, -1.00000, -1.00... \n", "4 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "5 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "6 (-1.00000, -1.00000, -1.00000, -1.00000, -0.77... \n", "7 (-1.00000, -0.77020, -0.62750, -0.55620, -0.46... \n", "8 (-0.55620, -0.46280, -0.38850, -0.29730, -0.07... \n", "9 (-0.29730, -0.07284, -0.03683, -0.02482, 0.00596) \n", "10 (-0.02482, 0.00596, 0.06049, 0.42900, 0.62750) \n", "11 (0.42900, 0.62750, 0.77020, 0.77020, 0.77020) \n", "\n", " 17 \\\n", "0 (0.77020, 0.68600, 0.66230, 0.24230, 0.22210) \n", "1 (0.24230, 0.22210, 0.28620, -0.19030, -0.57220) \n", "2 (-0.19030, -0.57220, -0.71820, -0.77020, -1.00... \n", "3 (-0.77020, -1.00000, -1.00000, -1.00000, -1.00... \n", "4 (-1.00000, -1.00000, -1.00000, -1.00000, -0.77... \n", "5 (-1.00000, -0.77020, -0.77020, -0.77020, -1.00... \n", "6 (-0.77020, -1.00000, -0.77020, -0.77020, -0.77... \n", "7 (-0.77020, -0.77020, -0.62750, -0.44960, 0.12230) \n", "8 (-0.44960, 0.12230, 0.19120, 0.08537, 0.29360) \n", "9 (0.08537, 0.29360, 0.40160, 0.38440, 0.39280) \n", "10 (0.38440, 0.39280, 0.44040, 0.46280, 0.64330) \n", "11 (0.46280, 0.64330, 0.60180, 0.71820, 0.77020) \n", "\n", " 18 \\\n", "0 (-1.00000, -1.00000, -0.71820, -0.35970, -0.17... \n", "1 (-0.35970, -0.17000, -0.05148, 0.29480, 0.14400) \n", "2 (0.29480, 0.14400, 0.47750, 0.61380, 0.66230) \n", "3 (0.61380, 0.66230, 0.71820, 0.71820, 0.71820) \n", "4 (0.71820, 0.71820, 0.71820, 0.77020, 0.71820) \n", "5 (0.77020, 0.71820, 0.77020, 0.77020, 0.77020) \n", "6 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "7 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "8 (0.77020, 0.77020, 0.71820, 0.71820, 0.57220) \n", "9 (0.71820, 0.57220, 0.28860, 0.31320, -0.46280) \n", "10 (0.31320, -0.46280, -0.77020, -0.42900, -0.71820) \n", "11 (-0.42900, -0.71820, -0.64330, -0.57220, -0.77... \n", "\n", " 19 \n", "0 (-1.00000, -1.00000, -1.00000, -1.00000, -1.00... \n", "1 (-1.00000, -1.00000, -0.48980, -0.53580, -0.39... \n", "2 (-0.53580, -0.39490, -0.16840, -0.01601, -0.05... \n", "3 (-0.01601, -0.05212, -0.07809, 0.52400, 0.54900) \n", "4 (0.52400, 0.54900, 0.71820, 0.77020, 0.77020) \n", "5 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "6 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "7 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "8 (0.77020, 0.77020, 0.77020, 0.77020, 0.77020) \n", "9 (0.77020, 0.77020, 0.68600, 0.50330, 0.52970) \n", "10 (0.50330, 0.52970, 0.57220, 0.62750, 0.66230) \n", "11 (0.62750, 0.66230, 0.53580, 0.45280, 0.29860) \n", "\n" ] } ], "source": [ "rol = rolling_window(df, 5, 3)\n", "print(rol)\n", "print(type(rol))" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{(Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000')): 23,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.77020')): 2,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.77020'),\n", " Decimal('-0.47750')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.66230'),\n", " Decimal('-0.47750')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.38230'),\n", " Decimal('-0.19620')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.34290'),\n", " Decimal('0.19200')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.77020'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.77020')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.77020'),\n", " Decimal('-0.77020'),\n", " Decimal('-0.77020')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.77020'),\n", " Decimal('-0.77020'),\n", " Decimal('-0.52400')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.71820'),\n", " Decimal('-0.71820'),\n", " Decimal('-0.66230')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.71820'),\n", " Decimal('-0.64330'),\n", " Decimal('-0.51840')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.71820'),\n", " Decimal('-0.64330'),\n", " Decimal('-0.45940')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.71820'),\n", " Decimal('-0.36330'),\n", " Decimal('-0.39710')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.71820'),\n", " Decimal('-0.35970'),\n", " Decimal('-0.17000')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.68600'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.66230')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.62750'),\n", " Decimal('-0.10080'),\n", " Decimal('0.11880')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.48980'),\n", " Decimal('-0.53580'),\n", " Decimal('-0.39490')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-0.77020'),\n", " Decimal('-0.77020'),\n", " Decimal('-0.77020'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-0.77020'),\n", " Decimal('-0.62750'),\n", " Decimal('-0.55620'),\n", " Decimal('-0.46280')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-0.77020'),\n", " Decimal('-0.62750'),\n", " Decimal('-0.27560'),\n", " Decimal('-0.27910')): 1,\n", " (Decimal('-1.00000'),\n", " Decimal('-0.66230'),\n", " Decimal('-0.57220'),\n", " Decimal('-0.49410'),\n", " Decimal('-0.39940')): 1,\n", " (Decimal('-0.77020'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000')): 4,\n", " (Decimal('-0.77020'),\n", " Decimal('-1.00000'),\n", " Decimal('-0.77020'),\n", " Decimal('-0.77020'),\n", " Decimal('-0.77020')): 1,\n", " (Decimal('-0.77020'),\n", " Decimal('-0.77020'),\n", " Decimal('-0.62750'),\n", " Decimal('-0.44960'),\n", " Decimal('0.12230')): 1,\n", " (Decimal('-0.77020'),\n", " Decimal('-0.52400'),\n", " Decimal('-0.27670'),\n", " Decimal('0.07677'),\n", " Decimal('0.48980')): 1,\n", " (Decimal('-0.77020'),\n", " Decimal('-0.47750'),\n", " Decimal('-0.71820'),\n", " Decimal('-0.37440'),\n", " Decimal('-0.04573')): 1,\n", " (Decimal('-0.71820'),\n", " Decimal('-0.77020'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-0.71820'),\n", " Decimal('-0.68600'),\n", " Decimal('-0.66230'),\n", " Decimal('-0.71820'),\n", " Decimal('-0.77020')): 1,\n", " (Decimal('-0.71820'),\n", " Decimal('-0.66230'),\n", " Decimal('-0.28860'),\n", " Decimal('-0.12660'),\n", " Decimal('0.16140')): 1,\n", " (Decimal('-0.66230'),\n", " Decimal('-0.47750'),\n", " Decimal('-0.24130'),\n", " Decimal('-0.08404'),\n", " Decimal('0.21290')): 1,\n", " (Decimal('-0.64330'),\n", " Decimal('-0.51840'),\n", " Decimal('-0.41350'),\n", " Decimal('-0.35110'),\n", " Decimal('-0.26110')): 1,\n", " (Decimal('-0.64330'),\n", " Decimal('-0.45940'),\n", " Decimal('-0.38640'),\n", " Decimal('-0.17080'),\n", " Decimal('-0.00721')): 1,\n", " (Decimal('-0.61380'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-0.60180'),\n", " Decimal('-0.71820'),\n", " Decimal('-0.77020'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-0.59100'),\n", " Decimal('-0.71820'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-0.57220'),\n", " Decimal('-0.71820'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-0.55620'),\n", " Decimal('-0.53580'),\n", " Decimal('-0.46280'),\n", " Decimal('-0.44040'),\n", " Decimal('-0.41590')): 1,\n", " (Decimal('-0.55620'),\n", " Decimal('-0.46280'),\n", " Decimal('-0.38850'),\n", " Decimal('-0.29730'),\n", " Decimal('-0.07284')): 1,\n", " (Decimal('-0.54900'),\n", " Decimal('-0.71820'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-0.53580'),\n", " Decimal('-0.39490'),\n", " Decimal('-0.16840'),\n", " Decimal('-0.01601'),\n", " Decimal('-0.05212')): 1,\n", " (Decimal('-0.51840'),\n", " Decimal('-0.34130'),\n", " Decimal('-0.57220'),\n", " Decimal('-0.71820'),\n", " Decimal('-0.68600')): 1,\n", " (Decimal('-0.51320'),\n", " Decimal('-0.49410'),\n", " Decimal('-0.51840'),\n", " Decimal('-0.32600'),\n", " Decimal('0.23540')): 1,\n", " (Decimal('-0.49410'),\n", " Decimal('-0.39940'),\n", " Decimal('-0.46280'),\n", " Decimal('-0.42370'),\n", " Decimal('-0.31050')): 1,\n", " (Decimal('-0.44960'),\n", " Decimal('0.12230'),\n", " Decimal('0.19120'),\n", " Decimal('0.08537'),\n", " Decimal('0.29360')): 1,\n", " (Decimal('-0.44040'),\n", " Decimal('-0.41590'),\n", " Decimal('-0.42900'),\n", " Decimal('-0.39280'),\n", " Decimal('-0.44040')): 1,\n", " (Decimal('-0.42900'),\n", " Decimal('-0.71820'),\n", " Decimal('-0.64330'),\n", " Decimal('-0.57220'),\n", " Decimal('-0.77020')): 1,\n", " (Decimal('-0.42370'),\n", " Decimal('-0.31050'),\n", " Decimal('-0.39710'),\n", " Decimal('-0.41850'),\n", " Decimal('-0.44040')): 1,\n", " (Decimal('-0.41850'),\n", " Decimal('-0.44040'),\n", " Decimal('-0.47000'),\n", " Decimal('-0.40860'),\n", " Decimal('0.09541')): 1,\n", " (Decimal('-0.40860'),\n", " Decimal('-0.29480'),\n", " Decimal('-0.22580'),\n", " Decimal('-0.61380'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-0.40860'),\n", " Decimal('0.09541'),\n", " Decimal('0.30120'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('-0.39280'),\n", " Decimal('-0.44040'),\n", " Decimal('-0.51320'),\n", " Decimal('-0.57220'),\n", " Decimal('-0.71820')): 1,\n", " (Decimal('-0.38230'),\n", " Decimal('-0.19620'),\n", " Decimal('0.06827'),\n", " Decimal('0.47000'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('-0.37640'),\n", " Decimal('-0.38030'),\n", " Decimal('-0.38030'),\n", " Decimal('-0.38030'),\n", " Decimal('-0.39060')): 1,\n", " (Decimal('-0.37440'),\n", " Decimal('-0.54220'),\n", " Decimal('-0.68600'),\n", " Decimal('-0.77020'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-0.37440'),\n", " Decimal('-0.04573'),\n", " Decimal('0.24950'),\n", " Decimal('0.54220'),\n", " Decimal('0.44340')): 1,\n", " (Decimal('-0.36330'),\n", " Decimal('-0.39710'),\n", " Decimal('-0.32020'),\n", " Decimal('-0.27790'),\n", " Decimal('-0.27440')): 1,\n", " (Decimal('-0.35970'),\n", " Decimal('-0.17000'),\n", " Decimal('-0.05148'),\n", " Decimal('0.29480'),\n", " Decimal('0.14400')): 1,\n", " (Decimal('-0.35110'),\n", " Decimal('-0.26110'),\n", " Decimal('-0.15070'),\n", " Decimal('0.15530'),\n", " Decimal('0.34130')): 1,\n", " (Decimal('-0.34290'),\n", " Decimal('0.19200'),\n", " Decimal('0.47000'),\n", " Decimal('0.71820'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('-0.33350'),\n", " Decimal('-0.61380'),\n", " Decimal('-0.55620'),\n", " Decimal('-0.55620'),\n", " Decimal('-0.53580')): 1,\n", " (Decimal('-0.32600'),\n", " Decimal('0.23540'),\n", " Decimal('0.60180'),\n", " Decimal('0.71820'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('-0.29730'),\n", " Decimal('-0.07284'),\n", " Decimal('-0.03683'),\n", " Decimal('-0.02482'),\n", " Decimal('0.00596')): 1,\n", " (Decimal('-0.29480'),\n", " Decimal('-0.31880'),\n", " Decimal('-0.37060'),\n", " Decimal('-0.37640'),\n", " Decimal('-0.38030')): 1,\n", " (Decimal('-0.28140'),\n", " Decimal('-0.25570'),\n", " Decimal('-0.17480'),\n", " Decimal('-0.05662'),\n", " Decimal('0.01915')): 1,\n", " (Decimal('-0.27790'),\n", " Decimal('-0.27440'),\n", " Decimal('-0.25890'),\n", " Decimal('-0.26540'),\n", " Decimal('-0.27220')): 1,\n", " (Decimal('-0.27790'),\n", " Decimal('-0.24950'),\n", " Decimal('-0.27670'),\n", " Decimal('-0.28140'),\n", " Decimal('-0.25570')): 1,\n", " (Decimal('-0.27560'),\n", " Decimal('-0.27910'),\n", " Decimal('-0.02671'),\n", " Decimal('0.17800'),\n", " Decimal('0.52970')): 1,\n", " (Decimal('-0.26540'),\n", " Decimal('-0.27220'),\n", " Decimal('-0.27910'),\n", " Decimal('-0.27790'),\n", " Decimal('-0.24950')): 1,\n", " (Decimal('-0.25260'),\n", " Decimal('-0.71820'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-0.24640'),\n", " Decimal('-0.53580'),\n", " Decimal('-0.50330'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-0.20230'),\n", " Decimal('-0.24030'),\n", " Decimal('-0.18120'),\n", " Decimal('0.00157'),\n", " Decimal('0.24740')): 1,\n", " (Decimal('-0.19030'),\n", " Decimal('-0.57220'),\n", " Decimal('-0.71820'),\n", " Decimal('-0.77020'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-0.17080'),\n", " Decimal('-0.00721'),\n", " Decimal('0.12020'),\n", " Decimal('0.29360'),\n", " Decimal('0.31740')): 1,\n", " (Decimal('-0.15300'),\n", " Decimal('-0.62750'),\n", " Decimal('-0.71820'),\n", " Decimal('-1.00000'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-0.15220'),\n", " Decimal('-0.47750'),\n", " Decimal('-0.15530'),\n", " Decimal('0.18620'),\n", " Decimal('0.39490')): 1,\n", " (Decimal('-0.15070'),\n", " Decimal('0.51840'),\n", " Decimal('0.55620'),\n", " Decimal('0.57220'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('-0.12660'),\n", " Decimal('0.16140'),\n", " Decimal('0.49410'),\n", " Decimal('0.50810'),\n", " Decimal('0.60180')): 1,\n", " (Decimal('-0.10080'),\n", " Decimal('0.11880'),\n", " Decimal('0.39490'),\n", " Decimal('0.21650'),\n", " Decimal('0.02860')): 1,\n", " (Decimal('-0.09138'),\n", " Decimal('-0.14330'),\n", " Decimal('-0.26110'),\n", " Decimal('-0.29480'),\n", " Decimal('-0.31880')): 1,\n", " (Decimal('-0.08404'),\n", " Decimal('0.21290'),\n", " Decimal('0.31880'),\n", " Decimal('0.48560'),\n", " Decimal('0.61380')): 1,\n", " (Decimal('-0.07941'),\n", " Decimal('-0.35970'),\n", " Decimal('-0.44960'),\n", " Decimal('-0.60180'),\n", " Decimal('-0.71820')): 1,\n", " (Decimal('-0.05662'),\n", " Decimal('0.01915'),\n", " Decimal('0.08404'),\n", " Decimal('0.11600'),\n", " Decimal('0.14620')): 1,\n", " (Decimal('-0.04892'),\n", " Decimal('-0.20230'),\n", " Decimal('-0.54220'),\n", " Decimal('-0.59100'),\n", " Decimal('-0.71820')): 1,\n", " (Decimal('-0.02482'),\n", " Decimal('0.00596'),\n", " Decimal('0.06049'),\n", " Decimal('0.42900'),\n", " Decimal('0.62750')): 1,\n", " (Decimal('-0.01601'),\n", " Decimal('-0.05212'),\n", " Decimal('-0.07809'),\n", " Decimal('0.52400'),\n", " Decimal('0.54900')): 1,\n", " (Decimal('0.00157'),\n", " Decimal('0.24740'),\n", " Decimal('0.37440'),\n", " Decimal('0.48560'),\n", " Decimal('0.41590')): 1,\n", " (Decimal('0.00533'),\n", " Decimal('0.04064'),\n", " Decimal('0.06502'),\n", " Decimal('0.12730'),\n", " Decimal('-0.03239')): 1,\n", " (Decimal('0.03936'),\n", " Decimal('-0.09406'),\n", " Decimal('0.11460'),\n", " Decimal('0.45600'),\n", " Decimal('0.71820')): 1,\n", " (Decimal('0.04191'),\n", " Decimal('-0.30380'),\n", " Decimal('-0.64330'),\n", " Decimal('-0.77020'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('0.07415'),\n", " Decimal('0.27220'),\n", " Decimal('-0.20750'),\n", " Decimal('-0.51840'),\n", " Decimal('-0.34130')): 1,\n", " (Decimal('0.07677'),\n", " Decimal('0.48980'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.08073'),\n", " Decimal('0.09947'),\n", " Decimal('-0.25360'),\n", " Decimal('-0.21200'),\n", " Decimal('-0.29360')): 1,\n", " (Decimal('0.08537'),\n", " Decimal('0.29360'),\n", " Decimal('0.40160'),\n", " Decimal('0.38440'),\n", " Decimal('0.39280')): 1,\n", " (Decimal('0.15530'),\n", " Decimal('0.34130'),\n", " Decimal('0.77020'),\n", " Decimal('0.51840'),\n", " Decimal('0.71820')): 1,\n", " (Decimal('0.15910'),\n", " Decimal('-0.07284'),\n", " Decimal('-0.02104'),\n", " Decimal('0.00533'),\n", " Decimal('0.04064')): 1,\n", " (Decimal('0.17800'),\n", " Decimal('0.52970'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.17960'),\n", " Decimal('0.00157'),\n", " Decimal('-0.19880'),\n", " Decimal('-0.40860'),\n", " Decimal('-0.29480')): 1,\n", " (Decimal('0.18040'),\n", " Decimal('0.30250'),\n", " Decimal('-0.03619'),\n", " Decimal('-0.51320'),\n", " Decimal('-0.49410')): 1,\n", " (Decimal('0.18620'),\n", " Decimal('0.39490'),\n", " Decimal('0.44960'),\n", " Decimal('0.46640'),\n", " Decimal('0.51840')): 1,\n", " (Decimal('0.21560'),\n", " Decimal('0.15760'),\n", " Decimal('0.13450'),\n", " Decimal('-0.33350'),\n", " Decimal('-0.61380')): 1,\n", " (Decimal('0.21650'),\n", " Decimal('0.02860'),\n", " Decimal('0.38440'),\n", " Decimal('0.56390'),\n", " Decimal('0.62750')): 1,\n", " (Decimal('0.22210'),\n", " Decimal('-0.21020'),\n", " Decimal('-0.01098'),\n", " Decimal('0.18040'),\n", " Decimal('0.30250')): 1,\n", " (Decimal('0.24230'),\n", " Decimal('0.22210'),\n", " Decimal('0.28620'),\n", " Decimal('-0.19030'),\n", " Decimal('-0.57220')): 1,\n", " (Decimal('0.24640'),\n", " Decimal('-0.22390'),\n", " Decimal('-0.34940'),\n", " Decimal('-0.77020'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('0.25150'),\n", " Decimal('0.21650'),\n", " Decimal('0.13590'),\n", " Decimal('0.15910'),\n", " Decimal('-0.07284')): 1,\n", " (Decimal('0.27910'),\n", " Decimal('0.39060'),\n", " Decimal('0.61380'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.28140'),\n", " Decimal('0.28860'),\n", " Decimal('0.27100'),\n", " Decimal('0.25150'),\n", " Decimal('0.21650')): 1,\n", " (Decimal('0.29230'),\n", " Decimal('0.07349'),\n", " Decimal('-0.21740'),\n", " Decimal('-0.50810'),\n", " Decimal('-1.00000')): 1,\n", " (Decimal('0.29480'),\n", " Decimal('0.14400'),\n", " Decimal('0.47750'),\n", " Decimal('0.61380'),\n", " Decimal('0.66230')): 1,\n", " (Decimal('0.30780'),\n", " Decimal('0.25790'),\n", " Decimal('0.14180'),\n", " Decimal('0.07809'),\n", " Decimal('0.04701')): 1,\n", " (Decimal('0.30910'),\n", " Decimal('0.27440'),\n", " Decimal('0.27330'),\n", " Decimal('0.26430'),\n", " Decimal('0.24740')): 1,\n", " (Decimal('0.31320'),\n", " Decimal('-0.46280'),\n", " Decimal('-0.77020'),\n", " Decimal('-0.42900'),\n", " Decimal('-0.71820')): 1,\n", " (Decimal('0.33350'),\n", " Decimal('0.33500'),\n", " Decimal('0.33660'),\n", " Decimal('0.30910'),\n", " Decimal('0.27440')): 1,\n", " (Decimal('0.33660'),\n", " Decimal('0.36150'),\n", " Decimal('0.20750'),\n", " Decimal('0.08073'),\n", " Decimal('0.09947')): 1,\n", " (Decimal('0.38440'),\n", " Decimal('0.39280'),\n", " Decimal('0.44040'),\n", " Decimal('0.46280'),\n", " Decimal('0.64330')): 1,\n", " (Decimal('0.41590'),\n", " Decimal('0.37640'),\n", " Decimal('0.36880'),\n", " Decimal('0.33350'),\n", " Decimal('0.33500')): 1,\n", " (Decimal('0.42370'),\n", " Decimal('0.41590'),\n", " Decimal('-0.13160'),\n", " Decimal('-0.24640'),\n", " Decimal('-0.53580')): 1,\n", " (Decimal('0.42900'),\n", " Decimal('0.62750'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.44640'),\n", " Decimal('0.27790'),\n", " Decimal('0.12230'),\n", " Decimal('-0.09138'),\n", " Decimal('-0.14330')): 1,\n", " (Decimal('0.45600'),\n", " Decimal('0.71820'),\n", " Decimal('0.77020'),\n", " Decimal('0.64330'),\n", " Decimal('0.39710')): 1,\n", " (Decimal('0.46280'),\n", " Decimal('0.64330'),\n", " Decimal('0.60180'),\n", " Decimal('0.71820'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.47000'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.48560'),\n", " Decimal('0.41590'),\n", " Decimal('0.27790'),\n", " Decimal('-0.04892'),\n", " Decimal('-0.20230')): 1,\n", " (Decimal('0.48560'),\n", " Decimal('0.54220'),\n", " Decimal('0.50330'),\n", " Decimal('0.46280'),\n", " Decimal('0.45940')): 1,\n", " (Decimal('0.48560'),\n", " Decimal('0.61380'),\n", " Decimal('0.71820'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.50330'),\n", " Decimal('0.45280'),\n", " Decimal('0.43750'),\n", " Decimal('0.41590'),\n", " Decimal('0.37640')): 1,\n", " (Decimal('0.50330'),\n", " Decimal('0.52970'),\n", " Decimal('0.57220'),\n", " Decimal('0.62750'),\n", " Decimal('0.66230')): 1,\n", " (Decimal('0.50810'),\n", " Decimal('0.60180'),\n", " Decimal('0.66230'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.51320'),\n", " Decimal('0.43750'),\n", " Decimal('0.30250'),\n", " Decimal('0.29230'),\n", " Decimal('0.07349')): 1,\n", " (Decimal('0.51840'),\n", " Decimal('0.46640'),\n", " Decimal('0.39280'),\n", " Decimal('0.30780'),\n", " Decimal('0.25790')): 1,\n", " (Decimal('0.51840'),\n", " Decimal('0.71820'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.52400'),\n", " Decimal('0.51840'),\n", " Decimal('0.52970'),\n", " Decimal('0.52970'),\n", " Decimal('0.54900')): 1,\n", " (Decimal('0.52400'),\n", " Decimal('0.54900'),\n", " Decimal('0.71820'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.52970'),\n", " Decimal('0.54900'),\n", " Decimal('0.55620'),\n", " Decimal('0.57220'),\n", " Decimal('0.56390')): 1,\n", " (Decimal('0.54220'),\n", " Decimal('0.44340'),\n", " Decimal('0.37830'),\n", " Decimal('0.66230'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.55620'),\n", " Decimal('0.05598'),\n", " Decimal('-0.44340'),\n", " Decimal('-0.44960'),\n", " Decimal('-0.64330')): 1,\n", " (Decimal('0.56390'),\n", " Decimal('0.62750'),\n", " Decimal('0.71820'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.57220'),\n", " Decimal('-1.00000'),\n", " Decimal('0.68600'),\n", " Decimal('0.03936'),\n", " Decimal('-0.09406')): 1,\n", " (Decimal('0.57220'),\n", " Decimal('0.56390'),\n", " Decimal('0.55620'),\n", " Decimal('0.51320'),\n", " Decimal('0.43750')): 1,\n", " (Decimal('0.57220'),\n", " Decimal('0.64330'),\n", " Decimal('0.71820'),\n", " Decimal('0.71820'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.58120'),\n", " Decimal('0.57220'),\n", " Decimal('0.51840'),\n", " Decimal('0.52400'),\n", " Decimal('0.51840')): 1,\n", " (Decimal('0.60180'),\n", " Decimal('0.64330'),\n", " Decimal('0.66230'),\n", " Decimal('0.64330'),\n", " Decimal('0.52400')): 1,\n", " (Decimal('0.61380'),\n", " Decimal('0.66230'),\n", " Decimal('0.71820'),\n", " Decimal('0.71820'),\n", " Decimal('0.71820')): 1,\n", " (Decimal('0.62750'),\n", " Decimal('0.52400'),\n", " Decimal('0.44040'),\n", " Decimal('0.57220'),\n", " Decimal('0.64330')): 1,\n", " (Decimal('0.62750'),\n", " Decimal('0.66230'),\n", " Decimal('0.53580'),\n", " Decimal('0.45280'),\n", " Decimal('0.29860')): 1,\n", " (Decimal('0.64330'),\n", " Decimal('0.39710'),\n", " Decimal('0.30120'),\n", " Decimal('0.27910'),\n", " Decimal('0.39060')): 1,\n", " (Decimal('0.64330'),\n", " Decimal('0.52400'),\n", " Decimal('0.32600'),\n", " Decimal('-0.25260'),\n", " Decimal('-0.71820')): 1,\n", " (Decimal('0.64330'),\n", " Decimal('0.62750'),\n", " Decimal('0.62750'),\n", " Decimal('0.04191'),\n", " Decimal('-0.30380')): 1,\n", " (Decimal('0.66230'),\n", " Decimal('0.48980'),\n", " Decimal('0.18950'),\n", " Decimal('-0.07941'),\n", " Decimal('-0.35970')): 1,\n", " (Decimal('0.66230'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.68600'),\n", " Decimal('0.71820'),\n", " Decimal('0.71820'),\n", " Decimal('0.71820'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.71820'),\n", " Decimal('0.57220'),\n", " Decimal('0.28860'),\n", " Decimal('0.31320'),\n", " Decimal('-0.46280')): 1,\n", " (Decimal('0.71820'),\n", " Decimal('0.71820'),\n", " Decimal('0.68600'),\n", " Decimal('0.64330'),\n", " Decimal('0.62750')): 1,\n", " (Decimal('0.71820'),\n", " Decimal('0.71820'),\n", " Decimal('0.71820'),\n", " Decimal('0.77020'),\n", " Decimal('0.71820')): 1,\n", " (Decimal('0.71820'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.35450')): 1,\n", " (Decimal('0.71820'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.66230')): 1,\n", " (Decimal('0.71820'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 2,\n", " (Decimal('0.77020'),\n", " Decimal('0.35450'),\n", " Decimal('0.00157'),\n", " Decimal('-0.20230'),\n", " Decimal('-0.24030')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.51320'),\n", " Decimal('0.21560'),\n", " Decimal('0.28140'),\n", " Decimal('0.28860')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.66230'),\n", " Decimal('0.26220'),\n", " Decimal('0.24640'),\n", " Decimal('-0.22390')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.66230'),\n", " Decimal('0.38640'),\n", " Decimal('0.17960'),\n", " Decimal('0.00157')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.66230'),\n", " Decimal('0.56390'),\n", " Decimal('0.33660'),\n", " Decimal('0.36150')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.68600'),\n", " Decimal('0.51320'),\n", " Decimal('0.22210'),\n", " Decimal('-0.21020')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.68600'),\n", " Decimal('0.66230'),\n", " Decimal('0.24230'),\n", " Decimal('0.22210')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.71820'),\n", " Decimal('0.42630'),\n", " Decimal('0.48560'),\n", " Decimal('0.54220')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.71820'),\n", " Decimal('0.56390'),\n", " Decimal('0.07415'),\n", " Decimal('0.27220')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.71820'),\n", " Decimal('0.56390'),\n", " Decimal('0.21560'),\n", " Decimal('0.15760')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.71820'),\n", " Decimal('0.64330'),\n", " Decimal('0.50330'),\n", " Decimal('0.45280')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.71820'),\n", " Decimal('0.68600'),\n", " Decimal('0.58120'),\n", " Decimal('0.57220')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.71820'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.44040'),\n", " Decimal('0.51840'),\n", " Decimal('0.46640')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.44960'),\n", " Decimal('-0.15220'),\n", " Decimal('-0.47750')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.45940'),\n", " Decimal('0.44640'),\n", " Decimal('0.27790')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.53580'),\n", " Decimal('-0.15300'),\n", " Decimal('-0.62750')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.68600'),\n", " Decimal('0.50330'),\n", " Decimal('0.52970')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.71820'),\n", " Decimal('0.60180'),\n", " Decimal('0.64330')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.71820'),\n", " Decimal('0.62750'),\n", " Decimal('0.52400')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.71820'),\n", " Decimal('0.71820'),\n", " Decimal('0.57220')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.55620'),\n", " Decimal('0.05598')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.51320')): 1,\n", " (Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.66230')): 2,\n", " (Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.71820')): 5,\n", " (Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020'),\n", " Decimal('0.77020')): 26}" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def text_freq(iterable):\n", " d = dict()\n", " for df in iterable:\n", " assert type(df) is pd.DataFrame, 'Wrong type:' + str(type(df))\n", " for _,col in df.iteritems():\n", " for word, cnt in col.value_counts().iteritems():\n", " hashable = word # hashable to be used as index\n", " if hashable in d:\n", " d[hashable] += cnt\n", " else:\n", " d[hashable] = cnt\n", " return d\n", "\n", "text_freq((rol,))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.5" } }, "nbformat": 4, "nbformat_minor": 2 }