{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "The **import** keyword is used to import a library" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "6.123233995736766e-17\n" ] } ], "source": [ "import math\n", "print(math.cos(math.pi / 2))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pandas\n", "=======" ] }, { "cell_type": "code", "execution_count": 1, "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", "
col1col2col3col4
line1-0.8821252.1764520.163955-0.618232
line2-0.7215380.0355780.1800721.015987
line3-1.1623550.384632-0.6740920.162693
line4-1.399455-0.6985120.0394200.898408
line51.755342-0.073242-1.502503-0.586194
\n", "
" ], "text/plain": [ " col1 col2 col3 col4\n", "line1 -0.882125 2.176452 0.163955 -0.618232\n", "line2 -0.721538 0.035578 0.180072 1.015987\n", "line3 -1.162355 0.384632 -0.674092 0.162693\n", "line4 -1.399455 -0.698512 0.039420 0.898408\n", "line5 1.755342 -0.073242 -1.502503 -0.586194" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy\n", "import pandas\n", "rows = ['line1', 'line2', 'line3', 'line4', 'line5']\n", "cols = ['col1', 'col2', 'col3', 'col4']\n", "from IPython.display import display\n", "dataframe = pandas.DataFrame(numpy.random.randn(5,4), index=rows, columns=cols)\n", "display(dataframe)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "reorganise a **dataframe** from datas as a dictionary with tuples as keys\n", "-----------------------------------------------------------------------------------------------------" ] }, { "cell_type": "code", "execution_count": 2, "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", "
Column 1Column 2Column 3
0CeriseLanister14
1PaulDurand13
2PierreDupont16
3johnSnow12
\n", "
" ], "text/plain": [ " Column 1 Column 2 Column 3\n", "0 Cerise Lanister 14\n", "1 Paul Durand 13\n", "2 Pierre Dupont 16\n", "3 john Snow 12" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dico = {('john', 'Snow') : 12, ('Paul', 'Durand') : 13, (\"Pierre\", \"Dupont\") : 16, (\"Cerise\", \"Lanister\") : 14}\n", "import pandas\n", "df = pandas.Series(dico).reset_index()\n", "df.columns = ['Column 1', 'Column 2', 'Column 3']\n", "from IPython.display import display\n", "display(df)" ] } ], "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.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }