{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f1039720-9692-4605-adf9-d37651958e4c", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "from pandas import DataFrame, Series" ] }, { "cell_type": "code", "execution_count": 108, "id": "8d39819f-2cac-437f-b5fc-633ca7443f8a", "metadata": {}, "outputs": [], "source": [ "rs = DataFrame({0: range(10, 101, 10), 1: range(10, 20), 2: range(20, 40, 2)})" ] }, { "cell_type": "code", "execution_count": 109, "id": "eb69c292-79e3-4105-b10c-6f4f5c22074f", "metadata": {}, "outputs": [], "source": [ "rs.set_index(2, drop=False, inplace=True)" ] }, { "cell_type": "code", "execution_count": 110, "id": "d7976bb8-05cb-4924-a6e2-90ea8af85d9d", "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", "
012
2
20101020
22201122
24301224
26401326
28501428
30601530
32701632
34801734
36901836
381001938
\n", "
" ], "text/plain": [ " 0 1 2\n", "2 \n", "20 10 10 20\n", "22 20 11 22\n", "24 30 12 24\n", "26 40 13 26\n", "28 50 14 28\n", "30 60 15 30\n", "32 70 16 32\n", "34 80 17 34\n", "36 90 18 36\n", "38 100 19 38" ] }, "execution_count": 110, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs" ] }, { "cell_type": "code", "execution_count": 112, "id": "3c456100-4931-4fbd-a63d-531eaf735e70", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 112, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs.index.get_loc(rs[rs.index <= 31].index[-1])" ] }, { "cell_type": "code", "execution_count": 73, "id": "1a5a99bb-3fc4-458d-95b8-4e031f3e04c1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index([20, 22, 24, 26, 28, 30, 32, 34, 36, 38], dtype='int64', name=2)" ] }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs.index" ] }, { "cell_type": "code", "execution_count": 79, "id": "2d53ccef-72e1-4378-818f-b60682bbd8b7", "metadata": {}, "outputs": [], "source": [ "g = rs[rs.index <= 31].iloc[-1]" ] }, { "cell_type": "code", "execution_count": 87, "id": "7318351e-e185-4695-ada5-43596b4844e6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "np.int64(20)" ] }, "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rs.index[0]" ] }, { "cell_type": "code", "execution_count": 114, "id": "55441116-8c00-4fd1-94c8-939320c6dfc4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[25, 26, 27, 28, 29]" ] }, "execution_count": 114, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t = list(range(30))\n", "t[25:30]" ] }, { "cell_type": "code", "execution_count": 121, "id": "6ef28e4c-15a5-4fe5-aa66-10ba464f1256", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[6, 7, 8, 9]" ] }, "execution_count": 121, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t[6: 10]" ] }, { "cell_type": "code", "execution_count": 126, "id": "f15cf18c-54cb-4624-8d18-3998bde2b9ba", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "None\n" ] } ], "source": [ "p = 0 or None\n", "print(p)" ] }, { "cell_type": "code", "execution_count": null, "id": "47dd4064-dde6-4824-a12b-ecf334bf4ebe", "metadata": {}, "outputs": [], "source": [] } ], "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.11.4" } }, "nbformat": 4, "nbformat_minor": 5 }