{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "1. Załaduj bibliotekę `pandas`." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. Wczytaj dane z pliku *mieszkania.csv* do zmiennej i wyświetl 5 pierwszych wierczy." ] }, { "cell_type": "code", "execution_count": 3, "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", "
Unnamed: 0IdExpectedRoomsSqrMetersFloorLocation
001269000355.001Poznań Zawady
112320000379.0010Poznań Rataje ul. Orła Bialego
223146000131.211Poznań Nowe Miasto ul. Kawalerka W Nowym Bloku...
334189000244.002Poznań Grunwald Ogrody Jeżyce Centrum Łazarz u...
445480240265.251Poznań ul. Droga Dębińska 19
\n", "
" ], "text/plain": [ " Unnamed: 0 Id Expected Rooms SqrMeters Floor \\\n", "0 0 1 269000 3 55.00 1 \n", "1 1 2 320000 3 79.00 10 \n", "2 2 3 146000 1 31.21 1 \n", "3 3 4 189000 2 44.00 2 \n", "4 4 5 480240 2 65.25 1 \n", "\n", " Location \n", "0 Poznań Zawady \n", "1 Poznań Rataje ul. Orła Bialego \n", "2 Poznań Nowe Miasto ul. Kawalerka W Nowym Bloku... \n", "3 Poznań Grunwald Ogrody Jeżyce Centrum Łazarz u... \n", "4 Poznań ul. Droga Dębińska 19 " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_csv(\"./mieszkania.csv\")\n", "\n", "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "3. Znajdź informacje ilu pokojowe mieszkania są najpopularniejsze i ile ich jest." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2 2208\n", "3 1553\n", "1 620\n", "4 523\n", "5 81\n", "6 13\n", "10 1\n", "7 1\n", "Name: Rooms, dtype: int64" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df['Rooms'].value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "4. Znajdź 10 najtańszych mieszkań." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "5. Napisz funkcje ``find_borough(desc)``, która przyjmuje 1 argument typu *string* i zwróci jedną z dzielnic zdefiniowaną w liście ``dzielnice``. Funkcja ma zwrócić pierwszą (wzgledem kolejności) nazwę dzielnicy, która jest zawarta w ``desc``. Jeżeli żadna nazwa nie została odnaleziona, zwróć napis *Inne*." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def find_borough(desc):\n", " dzielnice = ['Stare Miasto',\n", " 'Wilda',\n", " 'Jeżyce',\n", " 'Rataje',\n", " 'Piątkowo',\n", " 'Winogrady',\n", " 'Miłostowo',\n", " 'Dębiec']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "6. Dodaj kolumnę ``Borough``, która będzie zawierać informacje o dzielnicach i powstanie z kolumny ``Localization``. Wykorzystaj do tego funkcję ``find_borough``." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "7. Wyświetl histogram przedstawiający liczbę ogłoszeń mieszkań z podziałem na dzielnice." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "8. Znajdź średnią cenę mieszkania n-pokojowego." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "303861.86277173914" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[df['Rooms'] == 2]['Expected'].mean()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "9. Znajdź dzielnice, które zawierają oferty mieszkań na 13 piętrze." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2195 Poznań Winogrady ul. Os. Wichrowe Wzgórze - Zm...\n", "2773 Poznań Stare Miasto Winogrady ul. Os. Zwycięstwa\n", "Name: Location, dtype: object" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.query('Floor == 13')['Location']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "10. Znajdź wszystkie ogłoszenia mieszkań, które znajdują się na Winogradach, mają 3 pokoje i są położone na 1 piętrze." ] }, { "cell_type": "code", "execution_count": null, "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.13" } }, "nbformat": 4, "nbformat_minor": 2 }