{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Scale Values" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%config Completer.use_jedi = False" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Values can be associated to scales in one object instance.\n", "They are internally represented as `pandas.Series`." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from mcda.values import Values" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "values = Values([0, -2, 5, 10, 3])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Any type compatible with the `pandas.Series` constructor can be used to supply values." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 0.166667\n", "1 0.000000\n", "2 0.583333\n", "3 1.000000\n", "4 0.416667\n", "dtype: float64" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from mcda import normalize\n", "\n", "normalize(values).data" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "3 10\n", "2 5\n", "4 3\n", "0 0\n", "1 -2\n", "dtype: int64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "values.sort().data" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "values.is_within_scales" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can acess individual values and iterate over them as you would with an immutable mapping:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "values[0]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "values[0].value" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 -> Value(value=0, scale=QuantitativeScale(interval=[-2, 10]))\n", "1 -> Value(value=-2, scale=QuantitativeScale(interval=[-2, 10]))\n", "2 -> Value(value=5, scale=QuantitativeScale(interval=[-2, 10]))\n", "3 -> Value(value=10, scale=QuantitativeScale(interval=[-2, 10]))\n", "4 -> Value(value=3, scale=QuantitativeScale(interval=[-2, 10]))\n" ] } ], "source": [ "for k, v in values.items():\n", " print(f\"{k} -> {v}\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.7" }, "vscode": { "interpreter": { "hash": "949777d72b0d2535278d3dc13498b2535136f6dfe0678499012e853ee9abcab1" } } }, "nbformat": 4, "nbformat_minor": 2 }