{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "7f99860f", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": null, "id": "45c65a87", "metadata": {}, "outputs": [], "source": [ "df=pd.read_excel('rentingMedia.xlsx',sheet_name='rent')\n", "df1=df.set_index('price').T.reset_index()\n", "df1['date']=pd.to_datetime(df1['index'], format='%d%m%Y').dt.date\n", "df1=df1.set_index(['date']).drop('index',axis=1)\n", "df1" ] }, { "cell_type": "markdown", "id": "bcbcdf24", "metadata": {}, "source": [ "## Pandas\n", "\n", "* Pandas as wrapper instead of usin" ] }, { "cell_type": "code", "execution_count": null, "id": "32ce97dd", "metadata": {}, "outputs": [], "source": [ "ts=df1[['Ajuda', 'Alvalade','Areeiro']].plot(subplots=True,color='blue',figsize=(10, 20))\n" ] }, { "cell_type": "code", "execution_count": null, "id": "8e43212a", "metadata": {}, "outputs": [], "source": [ "ts=df1[['Ajuda', 'Alvalade','Parque das Nações']].plot(figsize=(10, 10))" ] }, { "cell_type": "code", "execution_count": null, "id": "780adb87", "metadata": {}, "outputs": [], "source": [ "ts=df1[['Ajuda', 'Alvalade','Parque das Nações']].plot.bar(figsize=(15, 5))" ] }, { "cell_type": "code", "execution_count": null, "id": "68104597", "metadata": {}, "outputs": [], "source": [ "ts=df1.plot.scatter('Alvalade','Parque das Nações')" ] }, { "cell_type": "code", "execution_count": null, "id": "3fd13bed", "metadata": {}, "outputs": [], "source": [ "df2=df1[['Ajuda', 'Alvalade','Areeiro']].reset_index().astype('str').set_index('date').T[['2022-01-01']]" ] }, { "cell_type": "code", "execution_count": null, "id": "b4da05ce", "metadata": {}, "outputs": [], "source": [ "df2['invesments']=df2[['2022-01-01']].astype(float)" ] }, { "cell_type": "code", "execution_count": null, "id": "87fc154d", "metadata": {}, "outputs": [], "source": [ "ts=df2.plot.pie(y='invesments', figsize=(5, 5))" ] }, { "attachments": {}, "cell_type": "markdown", "id": "e55f094c", "metadata": {}, "source": [ "## matplotlib\n", "\n", "* https://matplotlib.org/stable/\n", "* one of the best-known Python packages for plotting 2D charts. \n", "* the package works around the classes Figure, Subplot and Axes. \n", "* the most popular python plotting library. \n", "* Usually, it is imported as plt.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "2926429f", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n" ] }, { "cell_type": "code", "execution_count": null, "id": "6dead39e", "metadata": {}, "outputs": [], "source": [ "pf=plt.plot(df1['Olivais'])" ] }, { "cell_type": "code", "execution_count": null, "id": "5a07bc50", "metadata": {}, "outputs": [], "source": [ "plt.subplots()\n", "plt.plot(df1['Olivais'])\n", "plt.plot(df1['Parque das Nações'])\n", "pf=plt.plot()" ] }, { "cell_type": "code", "execution_count": null, "id": "dabee06c", "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots()\n", "ax.plot(df1['Olivais'], label=\"Olivais\")\n", "ax.plot(df1['Parque das Nações'], label=\"Parque das Nações\")\n", "ax.plot(df1['Benfica'], label=\"Benfica\")\n", "ax.plot(df1['Beato'], label=\"Beato\")\n", "ax.plot(df1['Marvila'], label=\"Marvila\")\n", "ax.set_title('Renting Price m2')\n", "ax.legend()\n", "pf=ax.plot()" ] }, { "cell_type": "code", "execution_count": null, "id": "b6d6ce4d", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "ts = pd.Series(np.random.randn(100),index=pd.date_range('1/1/2022', periods=100))\n", "df = pd.DataFrame(np.random.randn(100, 4), index=ts.index, columns=list('ABCD'))\n", "df = df.cumsum()\n", "pf=df.plot()" ] }, { "cell_type": "code", "execution_count": null, "id": "d62679cb", "metadata": {}, "outputs": [], "source": [ "fig, axs = plt.subplots(2, 2,figsize=(15, 10))\n", "axs[0, 0].plot(df1['Parque das Nações'])\n", "axs[0, 0].set_title('Axis [0, 0]:Parque das Nações')\n", "axs[0, 1].plot(df1['Beato'], 'tab:orange')\n", "axs[0, 1].set_title('Axis [0, 1]:Beato')\n", "axs[1, 0].plot(df1['Benfica'], 'tab:pink')\n", "axs[1, 0].set_title('Axis [1, 0]: Benfica')\n", "axs[1, 1].plot(df1['Misericórdia'], 'tab:red')\n", "axs[1, 1].set_title('Axis [1, 1]: Misericórdia')\n" ] }, { "cell_type": "code", "execution_count": null, "id": "9ad55759", "metadata": {}, "outputs": [], "source": [ "c=[2,0,0,3,2,2,2,4,4,5]" ] }, { "cell_type": "code", "execution_count": null, "id": "a412e506", "metadata": {}, "outputs": [], "source": [ "from mpl_toolkits.mplot3d import axes3d\n", "import matplotlib.pyplot as plt\n", "from matplotlib import cm\n", "\n", "ax = plt.figure().add_subplot(projection='3d')\n", "\n", "\n", "X=df1['Parque das Nações']\n", "Y =df1['Beato']\n", "Z =df1['Belém']\n", "ax.scatter(X, Y,Z,c=c)\n", "\n", "\n", "\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "80dda20d", "metadata": {}, "outputs": [], "source": [ "f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)\n", "ax1.plot(df1['Olivais'])\n", "ax1.set_title('Sharing Y axis')\n", "ax2.scatter(df1['Parque das Nações'], df1['Olivais'])" ] }, { "cell_type": "markdown", "id": "710189d2", "metadata": {}, "source": [ "## Seaborn\n", "\n", "* is a Python data visualization library based on Matplotlib.\n", "* provides a high-level interface for creating attractive charts.\n", "* less lines than Matplotlib. \n" ] }, { "cell_type": "code", "execution_count": null, "id": "9d2ca6a8", "metadata": {}, "outputs": [], "source": [ "import seaborn as sns\n", "fig, ax = plt.subplots(figsize=(15,15)) \n", "ft=sns.heatmap(df1.corr(numeric_only=True), annot=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "9dee789e", "metadata": {}, "outputs": [], "source": [ "df2=df1[['Ajuda', 'Alvalade','Areeiro', 'Estrela','Avenidas Novas']]\n", "pf=sns.pairplot(df2) " ] }, { "cell_type": "code", "execution_count": null, "id": "1b60522f", "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.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }