{
"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",
" col1 | \n",
" col2 | \n",
" col3 | \n",
" col4 | \n",
"
\n",
" \n",
" \n",
" \n",
" line1 | \n",
" -0.882125 | \n",
" 2.176452 | \n",
" 0.163955 | \n",
" -0.618232 | \n",
"
\n",
" \n",
" line2 | \n",
" -0.721538 | \n",
" 0.035578 | \n",
" 0.180072 | \n",
" 1.015987 | \n",
"
\n",
" \n",
" line3 | \n",
" -1.162355 | \n",
" 0.384632 | \n",
" -0.674092 | \n",
" 0.162693 | \n",
"
\n",
" \n",
" line4 | \n",
" -1.399455 | \n",
" -0.698512 | \n",
" 0.039420 | \n",
" 0.898408 | \n",
"
\n",
" \n",
" line5 | \n",
" 1.755342 | \n",
" -0.073242 | \n",
" -1.502503 | \n",
" -0.586194 | \n",
"
\n",
" \n",
"
\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",
" Column 1 | \n",
" Column 2 | \n",
" Column 3 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Cerise | \n",
" Lanister | \n",
" 14 | \n",
"
\n",
" \n",
" 1 | \n",
" Paul | \n",
" Durand | \n",
" 13 | \n",
"
\n",
" \n",
" 2 | \n",
" Pierre | \n",
" Dupont | \n",
" 16 | \n",
"
\n",
" \n",
" 3 | \n",
" john | \n",
" Snow | \n",
" 12 | \n",
"
\n",
" \n",
"
\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
}