{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Python Basic\n", "\n", "* Python\n", "* PY\n" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 4\n", "1 3\n", "2 2\n", "3 1\n", "dtype: object" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pandas import Series \n", "\n", "Series(['4', '3', '2', '1'])" ] }, { "cell_type": "code", "execution_count": 43, "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", "
ab
X12
Y45
\n", "
" ], "text/plain": [ " a b\n", "X 1 2\n", "Y 4 5" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pandas import DataFrame\n", "\n", "df = DataFrame(data=[[1, 2, 3], [4, 5, 6]], columns=['a', 'b', 'c'], index=['X', 'Y'])\n", "df[['a', 'b']]" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# list comprehension\n", "\n", "[i**2 for i in range(10)]" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'bbb'" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "string = 'aaa' if 0>1 else 'bbb'\n", "string" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Bought', 'Bought', 'Bought', 'Bought', 'Bought']" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "['Bought']*5" ] } ], "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.7.8" } }, "nbformat": 4, "nbformat_minor": 4 }