{"cells":[{"cell_type":"markdown","source":["
\n","\n"],"metadata":{"id":"69fPupn0qdcl"}},{"cell_type":"markdown","metadata":{"id":"Vkf1B-vMwpVB"},"source":["# Introduction to Pandas\n","\n","[*pandas*](http://pandas.pydata.org/) is a column-oriented data analysis API. It's a great tool for handling and analyzing input data, and many ML frameworks support *pandas* data structures as inputs.\n","Although a comprehensive introduction to the *pandas* API would span many pages, the core concepts are fairly straightforward, and we'll present them below. For a more complete reference, the [*pandas* docs site](http://pandas.pydata.org/pandas-docs/stable/index.html) contains extensive documentation and many tutorials."]},{"cell_type":"markdown","metadata":{"id":"fpPtZgqIvuXz"},"source":["Inspiration and some of the parts came from: Python Data Science [GitHub repository](https://github.com/jakevdp/PythonDataScienceHandbook/tree/master), [MIT License](https://github.com/jakevdp/PythonDataScienceHandbook/blob/master/LICENSE-CODE) and [Introduction to Pandas](https://colab.research.google.com/notebooks/mlcc/intro_to_pandas.ipynb) by Google, [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)\n","\n","If running this from Google Colab, uncomment the cell below and run it. Otherwise, just skip it."]},{"cell_type":"code","execution_count":null,"metadata":{"id":"5saSBc40voZF"},"outputs":[],"source":["#!pip install watermark"]},{"cell_type":"markdown","metadata":{"id":"ZkUd2sa-yP5e"},"source":["## Learning Objectives:\n","\n"," * Gain an introduction to the *DataFrame* and *Series* data structures of the pandas library\n","\n"," * Import CSV data into a pandas *DataFrame*\n","\n"," * Access and manipulate data within a *DataFrame* and *Series*\n","\n"," * Export *DataFrame* to CSV"]},{"cell_type":"markdown","metadata":{"id":"ZSKZSsP4zbG9"},"source":["## Basic Concepts\n","\n","The following line imports the *pandas* API and prints the API version:"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":35},"executionInfo":{"elapsed":27,"status":"ok","timestamp":1692082105416,"user":{"displayName":"Martin Schätz","userId":"14609383414092679868"},"user_tz":-120},"id":"Vd5AD0ERy-OV","outputId":"7dbcf63b-b2bf-4b30-f851-b4cd0e4a4efa"},"outputs":[{"data":{"text/plain":["'2.0.3'"]},"execution_count":2,"metadata":{},"output_type":"execute_result"}],"source":["import pandas as pd\n","pd.__version__"]},{"cell_type":"markdown","metadata":{"id":"daQreKXIUslr"},"source":["The primary data structures in *pandas* are implemented as two classes:\n","\n"," * **`DataFrame`**, which you can imagine as a relational data table, with rows and named columns.\n"," * **`Series`**, which is a single column. A `DataFrame` contains one or more `Series` and a name for each `Series`.\n","\n","The data frame is a commonly used abstraction for data manipulation. Similar implementations exist in [Spark](https://spark.apache.org/) and [R](https://www.r-project.org/about.html)."]},{"cell_type":"markdown","metadata":{"id":"fjnAk1xcU0yc"},"source":["### pandas.Series\n","\n","One way to create a `Series` is to construct a `Series` object. For example:"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":26,"status":"ok","timestamp":1692082105417,"user":{"displayName":"Martin Schätz","userId":"14609383414092679868"},"user_tz":-120},"id":"DFZ42Uq7UFDj","outputId":"77c73b7e-9765-41aa-a111-926b7e48fc8b"},"outputs":[{"data":{"text/plain":["0 San Francisco\n","1 San Jose\n","2 Sacramento\n","dtype: object"]},"execution_count":3,"metadata":{},"output_type":"execute_result"}],"source":["pd.Series(['San Francisco', 'San Jose', 'Sacramento'])"]},{"cell_type":"markdown","metadata":{"id":"Szf-fsivqWxm"},"source":["### pandas.DataFrame"]},{"cell_type":"markdown","metadata":{"id":"U5ouUp1cU6pC"},"source":["`DataFrame` objects can be created by passing a `dict` mapping `string` column names to their respective `Series`. If the `Series` don't match in length, missing values are filled with special [NA/NaN](http://pandas.pydata.org/pandas-docs/stable/missing_data.html) values. Example:"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":143},"executionInfo":{"elapsed":24,"status":"ok","timestamp":1692082105417,"user":{"displayName":"Martin Schätz","userId":"14609383414092679868"},"user_tz":-120},"id":"avgr6GfiUh8t","outputId":"f760fa95-ff49-4e5b-c006-643dfa93b9b4"},"outputs":[{"data":{"text/html":["\n","\n","\n"," \n"," \n"," \n"," City name\n"," Population\n"," \n"," \n"," \n"," \n"," 0\n"," San Francisco\n"," 852469\n"," \n"," \n"," 1\n"," San Jose\n"," 1015785\n"," \n"," \n"," 2\n"," Sacramento\n"," 485199\n"," \n"," \n","\n",""],"text/plain":[" City name Population\n","0 San Francisco 852469\n","1 San Jose 1015785\n","2 Sacramento 485199"]},"execution_count":4,"metadata":{},"output_type":"execute_result"}],"source":["city_names = pd.Series(['San Francisco', 'San Jose', 'Sacramento'])\n","population = pd.Series([852469, 1015785, 485199])\n","\n","cities_dataframe = pd.DataFrame({ 'City name': city_names, 'Population': population })\n","cities_dataframe"]},{"cell_type":"markdown","metadata":{"id":"PKbp4rnyqWxo"},"source":["#### Reading a DataFrame from a file"]},{"cell_type":"markdown","metadata":{"id":"oa5wfZT7VHJl"},"source":["But most of the time, you load an entire file into a `DataFrame`. The following example loads a file with California housing data. Run the following cell to load the data and create feature definitions:"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":270},"executionInfo":{"elapsed":22,"status":"ok","timestamp":1692082105417,"user":{"displayName":"Martin Schätz","userId":"14609383414092679868"},"user_tz":-120},"id":"av6RYOraVG1V","outputId":"105f70fd-8d43-435a-942a-968f351cf7f0"},"outputs":[{"data":{"text/html":["\n","\n","\n"," \n"," \n"," \n"," longitude\n"," latitude\n"," housing_median_age\n"," total_rooms\n"," total_bedrooms\n"," population\n"," households\n"," median_income\n"," median_house_value\n"," \n"," \n"," \n"," \n"," 0\n"," -114.31\n"," 34.19\n"," 15.0\n"," 5612.0\n"," 1283.0\n"," 1015.0\n"," 472.0\n"," 1.4936\n"," 66900.0\n"," \n"," \n"," 1\n"," -114.47\n"," 34.40\n"," 19.0\n"," 7650.0\n"," 1901.0\n"," 1129.0\n"," 463.0\n"," 1.8200\n"," 80100.0\n"," \n"," \n"," 2\n"," -114.56\n"," 33.69\n"," 17.0\n"," 720.0\n"," 174.0\n"," 333.0\n"," 117.0\n"," 1.6509\n"," 85700.0\n"," \n"," \n"," 3\n"," -114.57\n"," 33.64\n"," 14.0\n"," 1501.0\n"," 337.0\n"," 515.0\n"," 226.0\n"," 3.1917\n"," 73400.0\n"," \n"," \n"," 4\n"," -114.57\n"," 33.57\n"," 20.0\n"," 1454.0\n"," 326.0\n"," 624.0\n"," 262.0\n"," 1.9250\n"," 65500.0\n"," \n"," \n","\n",""],"text/plain":[" longitude latitude housing_median_age total_rooms total_bedrooms \\\n","0 -114.31 34.19 15.0 5612.0 1283.0 \n","1 -114.47 34.40 19.0 7650.0 1901.0 \n","2 -114.56 33.69 17.0 720.0 174.0 \n","3 -114.57 33.64 14.0 1501.0 337.0 \n","4 -114.57 33.57 20.0 1454.0 326.0 \n","\n"," population households median_income median_house_value \n","0 1015.0 472.0 1.4936 66900.0 \n","1 1129.0 463.0 1.8200 80100.0 \n","2 333.0 117.0 1.6509 85700.0 \n","3 515.0 226.0 3.1917 73400.0 \n","4 624.0 262.0 1.9250 65500.0 "]},"execution_count":5,"metadata":{},"output_type":"execute_result"}],"source":["california_housing_dataframe = pd.read_csv(\"https://download.mlcc.google.com/mledu-datasets/california_housing_train.csv\", sep=\",\")\n","california_housing_dataframe.head()\n","#california_housing_dataframe.tail()"]},{"cell_type":"markdown","metadata":{"id":"JG_5tjH3zxqN"},"source":["If you need to take a peak to documentation, there is always fast way to use **?** after function."]},{"cell_type":"code","execution_count":null,"metadata":{"executionInfo":{"elapsed":23,"status":"ok","timestamp":1692082105418,"user":{"displayName":"Martin Schätz","userId":"14609383414092679868"},"user_tz":-120},"id":"JUy_7XeDzvU9","outputId":"4651b26a-87f9-4a59-f461-16d2d42bbcde"},"outputs":[{"name":"stdout","output_type":"stream","text":["\u001b[1;31mSignature:\u001b[0m\n","\u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mfilepath_or_buffer\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str]'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0msep\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str | None | lib.NoDefault'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m<\u001b[0m\u001b[0mno_default\u001b[0m\u001b[1;33m>\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mdelimiter\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str | None | lib.NoDefault'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mheader\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m\"int | Sequence[int] | None | Literal['infer']\"\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'infer'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mnames\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Sequence[Hashable] | None | lib.NoDefault'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m<\u001b[0m\u001b[0mno_default\u001b[0m\u001b[1;33m>\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mindex_col\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'IndexLabel | Literal[False] | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0musecols\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'DtypeArg | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mengine\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'CSVEngine | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mconverters\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mtrue_values\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mfalse_values\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mskipinitialspace\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mskiprows\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mskipfooter\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'int'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mnrows\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'int | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mna_values\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mkeep_default_na\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mna_filter\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mverbose\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mskip_blank_lines\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mparse_dates\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool | Sequence[Hashable] | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0minfer_datetime_format\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool | lib.NoDefault'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m<\u001b[0m\u001b[0mno_default\u001b[0m\u001b[1;33m>\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mkeep_date_col\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mdate_parser\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m<\u001b[0m\u001b[0mno_default\u001b[0m\u001b[1;33m>\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mdate_format\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mdayfirst\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mcache_dates\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0miterator\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mchunksize\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'int | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mcompression\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'CompressionOptions'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'infer'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mthousands\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mdecimal\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'.'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mlineterminator\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mquotechar\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'\"'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mquoting\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'int'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mdoublequote\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mescapechar\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mcomment\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mencoding\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mencoding_errors\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'strict'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mdialect\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str | csv.Dialect | None'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mon_bad_lines\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'error'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mdelim_whitespace\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mlow_memory\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mmemory_map\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mfloat_precision\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m\"Literal['high', 'legacy'] | None\"\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mstorage_options\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'StorageOptions'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m \u001b[0mdtype_backend\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'DtypeBackend | lib.NoDefault'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m<\u001b[0m\u001b[0mno_default\u001b[0m\u001b[1;33m>\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n","\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m->\u001b[0m \u001b[1;34m'DataFrame | TextFileReader'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n","\u001b[1;31mDocstring:\u001b[0m\n","Read a comma-separated values (csv) file into DataFrame.\n","\n","Also supports optionally iterating or breaking of the file\n","into chunks.\n","\n","Additional help can be found in the online docs for\n","`IO Tools `_.\n","\n","Parameters\n","----------\n","filepath_or_buffer : str, path object or file-like object\n"," Any valid string path is acceptable. The string could be a URL. Valid\n"," URL schemes include http, ftp, s3, gs, and file. For file URLs, a host is\n"," expected. A local file could be: file://localhost/path/to/table.csv.\n","\n"," If you want to pass in a path object, pandas accepts any ``os.PathLike``.\n","\n"," By file-like object, we refer to objects with a ``read()`` method, such as\n"," a file handle (e.g. via builtin ``open`` function) or ``StringIO``.\n","sep : str, default ','\n"," Delimiter to use. If sep is None, the C engine cannot automatically detect\n"," the separator, but the Python parsing engine can, meaning the latter will\n"," be used and automatically detect the separator by Python's builtin sniffer\n"," tool, ``csv.Sniffer``. In addition, separators longer than 1 character and\n"," different from ``'\\s+'`` will be interpreted as regular expressions and\n"," will also force the use of the Python parsing engine. Note that regex\n"," delimiters are prone to ignoring quoted data. Regex example: ``'\\r\\t'``.\n","delimiter : str, default ``None``\n"," Alias for sep.\n","header : int, list of int, None, default 'infer'\n"," Row number(s) to use as the column names, and the start of the\n"," data. Default behavior is to infer the column names: if no names\n"," are passed the behavior is identical to ``header=0`` and column\n"," names are inferred from the first line of the file, if column\n"," names are passed explicitly then the behavior is identical to\n"," ``header=None``. Explicitly pass ``header=0`` to be able to\n"," replace existing names. The header can be a list of integers that\n"," specify row locations for a multi-index on the columns\n"," e.g. [0,1,3]. Intervening rows that are not specified will be\n"," skipped (e.g. 2 in this example is skipped). Note that this\n"," parameter ignores commented lines and empty lines if\n"," ``skip_blank_lines=True``, so ``header=0`` denotes the first line of\n"," data rather than the first line of the file.\n","names : array-like, optional\n"," List of column names to use. If the file contains a header row,\n"," then you should explicitly pass ``header=0`` to override the column names.\n"," Duplicates in this list are not allowed.\n","index_col : int, str, sequence of int / str, or False, optional, default ``None``\n"," Column(s) to use as the row labels of the ``DataFrame``, either given as\n"," string name or column index. If a sequence of int / str is given, a\n"," MultiIndex is used.\n","\n"," Note: ``index_col=False`` can be used to force pandas to *not* use the first\n"," column as the index, e.g. when you have a malformed file with delimiters at\n"," the end of each line.\n","usecols : list-like or callable, optional\n"," Return a subset of the columns. If list-like, all elements must either\n"," be positional (i.e. integer indices into the document columns) or strings\n"," that correspond to column names provided either by the user in `names` or\n"," inferred from the document header row(s). If ``names`` are given, the document\n"," header row(s) are not taken into account. For example, a valid list-like\n"," `usecols` parameter would be ``[0, 1, 2]`` or ``['foo', 'bar', 'baz']``.\n"," Element order is ignored, so ``usecols=[0, 1]`` is the same as ``[1, 0]``.\n"," To instantiate a DataFrame from ``data`` with element order preserved use\n"," ``pd.read_csv(data, usecols=['foo', 'bar'])[['foo', 'bar']]`` for columns\n"," in ``['foo', 'bar']`` order or\n"," ``pd.read_csv(data, usecols=['foo', 'bar'])[['bar', 'foo']]``\n"," for ``['bar', 'foo']`` order.\n","\n"," If callable, the callable function will be evaluated against the column\n"," names, returning names where the callable function evaluates to True. An\n"," example of a valid callable argument would be ``lambda x: x.upper() in\n"," ['AAA', 'BBB', 'DDD']``. Using this parameter results in much faster\n"," parsing time and lower memory usage.\n","dtype : Type name or dict of column -> type, optional\n"," Data type for data or columns. E.g. {'a': np.float64, 'b': np.int32,\n"," 'c': 'Int64'}\n"," Use `str` or `object` together with suitable `na_values` settings\n"," to preserve and not interpret dtype.\n"," If converters are specified, they will be applied INSTEAD\n"," of dtype conversion.\n","\n"," .. versionadded:: 1.5.0\n","\n"," Support for defaultdict was added. Specify a defaultdict as input where\n"," the default determines the dtype of the columns which are not explicitly\n"," listed.\n","engine : {'c', 'python', 'pyarrow'}, optional\n"," Parser engine to use. The C and pyarrow engines are faster, while the python engine\n"," is currently more feature-complete. Multithreading is currently only supported by\n"," the pyarrow engine.\n","\n"," .. versionadded:: 1.4.0\n","\n"," The \"pyarrow\" engine was added as an *experimental* engine, and some features\n"," are unsupported, or may not work correctly, with this engine.\n","converters : dict, optional\n"," Dict of functions for converting values in certain columns. Keys can either\n"," be integers or column labels.\n","true_values : list, optional\n"," Values to consider as True in addition to case-insensitive variants of \"True\".\n","false_values : list, optional\n"," Values to consider as False in addition to case-insensitive variants of \"False\".\n","skipinitialspace : bool, default False\n"," Skip spaces after delimiter.\n","skiprows : list-like, int or callable, optional\n"," Line numbers to skip (0-indexed) or number of lines to skip (int)\n"," at the start of the file.\n","\n"," If callable, the callable function will be evaluated against the row\n"," indices, returning True if the row should be skipped and False otherwise.\n"," An example of a valid callable argument would be ``lambda x: x in [0, 2]``.\n","skipfooter : int, default 0\n"," Number of lines at bottom of file to skip (Unsupported with engine='c').\n","nrows : int, optional\n"," Number of rows of file to read. Useful for reading pieces of large files.\n","na_values : scalar, str, list-like, or dict, optional\n"," Additional strings to recognize as NA/NaN. If dict passed, specific\n"," per-column NA values. By default the following values are interpreted as\n"," NaN: '', '#N/A', '#N/A N/A', '#NA', '-1.#IND', '-1.#QNAN', '-NaN', '-nan',\n"," '1.#IND', '1.#QNAN', '', 'N/A', 'NA', 'NULL', 'NaN', 'None',\n"," 'n/a', 'nan', 'null'.\n","keep_default_na : bool, default True\n"," Whether or not to include the default NaN values when parsing the data.\n"," Depending on whether `na_values` is passed in, the behavior is as follows:\n","\n"," * If `keep_default_na` is True, and `na_values` are specified, `na_values`\n"," is appended to the default NaN values used for parsing.\n"," * If `keep_default_na` is True, and `na_values` are not specified, only\n"," the default NaN values are used for parsing.\n"," * If `keep_default_na` is False, and `na_values` are specified, only\n"," the NaN values specified `na_values` are used for parsing.\n"," * If `keep_default_na` is False, and `na_values` are not specified, no\n"," strings will be parsed as NaN.\n","\n"," Note that if `na_filter` is passed in as False, the `keep_default_na` and\n"," `na_values` parameters will be ignored.\n","na_filter : bool, default True\n"," Detect missing value markers (empty strings and the value of na_values). In\n"," data without any NAs, passing na_filter=False can improve the performance\n"," of reading a large file.\n","verbose : bool, default False\n"," Indicate number of NA values placed in non-numeric columns.\n","skip_blank_lines : bool, default True\n"," If True, skip over blank lines rather than interpreting as NaN values.\n","parse_dates : bool or list of int or names or list of lists or dict, default False\n"," The behavior is as follows:\n","\n"," * boolean. If True -> try parsing the index.\n"," * list of int or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3\n"," each as a separate date column.\n"," * list of lists. e.g. If [[1, 3]] -> combine columns 1 and 3 and parse as\n"," a single date column.\n"," * dict, e.g. {'foo' : [1, 3]} -> parse columns 1, 3 as date and call\n"," result 'foo'\n","\n"," If a column or index cannot be represented as an array of datetimes,\n"," say because of an unparsable value or a mixture of timezones, the column\n"," or index will be returned unaltered as an object data type. For\n"," non-standard datetime parsing, use ``pd.to_datetime`` after\n"," ``pd.read_csv``.\n","\n"," Note: A fast-path exists for iso8601-formatted dates.\n","infer_datetime_format : bool, default False\n"," If True and `parse_dates` is enabled, pandas will attempt to infer the\n"," format of the datetime strings in the columns, and if it can be inferred,\n"," switch to a faster method of parsing them. In some cases this can increase\n"," the parsing speed by 5-10x.\n","\n"," .. deprecated:: 2.0.0\n"," A strict version of this argument is now the default, passing it has no effect.\n","\n","keep_date_col : bool, default False\n"," If True and `parse_dates` specifies combining multiple columns then\n"," keep the original columns.\n","date_parser : function, optional\n"," Function to use for converting a sequence of string columns to an array of\n"," datetime instances. The default uses ``dateutil.parser.parser`` to do the\n"," conversion. Pandas will try to call `date_parser` in three different ways,\n"," advancing to the next if an exception occurs: 1) Pass one or more arrays\n"," (as defined by `parse_dates`) as arguments; 2) concatenate (row-wise) the\n"," string values from the columns defined by `parse_dates` into a single array\n"," and pass that; and 3) call `date_parser` once for each row using one or\n"," more strings (corresponding to the columns defined by `parse_dates`) as\n"," arguments.\n","\n"," .. deprecated:: 2.0.0\n"," Use ``date_format`` instead, or read in as ``object`` and then apply\n"," :func:`to_datetime` as-needed.\n","date_format : str or dict of column -> format, default ``None``\n"," If used in conjunction with ``parse_dates``, will parse dates according to this\n"," format. For anything more complex,\n"," please read in as ``object`` and then apply :func:`to_datetime` as-needed.\n","\n"," .. versionadded:: 2.0.0\n","dayfirst : bool, default False\n"," DD/MM format dates, international and European format.\n","cache_dates : bool, default True\n"," If True, use a cache of unique, converted dates to apply the datetime\n"," conversion. May produce significant speed-up when parsing duplicate\n"," date strings, especially ones with timezone offsets.\n","\n","iterator : bool, default False\n"," Return TextFileReader object for iteration or getting chunks with\n"," ``get_chunk()``.\n","\n"," .. versionchanged:: 1.2\n","\n"," ``TextFileReader`` is a context manager.\n","chunksize : int, optional\n"," Return TextFileReader object for iteration.\n"," See the `IO Tools docs\n"," `_\n"," for more information on ``iterator`` and ``chunksize``.\n","\n"," .. versionchanged:: 1.2\n","\n"," ``TextFileReader`` is a context manager.\n","compression : str or dict, default 'infer'\n"," For on-the-fly decompression of on-disk data. If 'infer' and 'filepath_or_buffer' is\n"," path-like, then detect compression from the following extensions: '.gz',\n"," '.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2'\n"," (otherwise no compression).\n"," If using 'zip' or 'tar', the ZIP file must contain only one data file to be read in.\n"," Set to ``None`` for no decompression.\n"," Can also be a dict with key ``'method'`` set\n"," to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'tar'``} and other\n"," key-value pairs are forwarded to\n"," ``zipfile.ZipFile``, ``gzip.GzipFile``,\n"," ``bz2.BZ2File``, ``zstandard.ZstdDecompressor`` or\n"," ``tarfile.TarFile``, respectively.\n"," As an example, the following could be passed for Zstandard decompression using a\n"," custom compression dictionary:\n"," ``compression={'method': 'zstd', 'dict_data': my_compression_dict}``.\n","\n"," .. versionadded:: 1.5.0\n"," Added support for `.tar` files.\n","\n"," .. versionchanged:: 1.4.0 Zstandard support.\n","\n","thousands : str, optional\n"," Thousands separator.\n","decimal : str, default '.'\n"," Character to recognize as decimal point (e.g. use ',' for European data).\n","lineterminator : str (length 1), optional\n"," Character to break file into lines. Only valid with C parser.\n","quotechar : str (length 1), optional\n"," The character used to denote the start and end of a quoted item. Quoted\n"," items can include the delimiter and it will be ignored.\n","quoting : int or csv.QUOTE_* instance, default 0\n"," Control field quoting behavior per ``csv.QUOTE_*`` constants. Use one of\n"," QUOTE_MINIMAL (0), QUOTE_ALL (1), QUOTE_NONNUMERIC (2) or QUOTE_NONE (3).\n","doublequote : bool, default ``True``\n"," When quotechar is specified and quoting is not ``QUOTE_NONE``, indicate\n"," whether or not to interpret two consecutive quotechar elements INSIDE a\n"," field as a single ``quotechar`` element.\n","escapechar : str (length 1), optional\n"," One-character string used to escape other characters.\n","comment : str, optional\n"," Indicates remainder of line should not be parsed. If found at the beginning\n"," of a line, the line will be ignored altogether. This parameter must be a\n"," single character. Like empty lines (as long as ``skip_blank_lines=True``),\n"," fully commented lines are ignored by the parameter `header` but not by\n"," `skiprows`. For example, if ``comment='#'``, parsing\n"," ``#empty\\na,b,c\\n1,2,3`` with ``header=0`` will result in 'a,b,c' being\n"," treated as the header.\n","encoding : str, optional, default \"utf-8\"\n"," Encoding to use for UTF when reading/writing (ex. 'utf-8'). `List of Python\n"," standard encodings\n"," `_ .\n","\n"," .. versionchanged:: 1.2\n","\n"," When ``encoding`` is ``None``, ``errors=\"replace\"`` is passed to\n"," ``open()``. Otherwise, ``errors=\"strict\"`` is passed to ``open()``.\n"," This behavior was previously only the case for ``engine=\"python\"``.\n","\n"," .. versionchanged:: 1.3.0\n","\n"," ``encoding_errors`` is a new argument. ``encoding`` has no longer an\n"," influence on how encoding errors are handled.\n","\n","encoding_errors : str, optional, default \"strict\"\n"," How encoding errors are treated. `List of possible values\n"," `_ .\n","\n"," .. versionadded:: 1.3.0\n","\n","dialect : str or csv.Dialect, optional\n"," If provided, this parameter will override values (default or not) for the\n"," following parameters: `delimiter`, `doublequote`, `escapechar`,\n"," `skipinitialspace`, `quotechar`, and `quoting`. If it is necessary to\n"," override values, a ParserWarning will be issued. See csv.Dialect\n"," documentation for more details.\n","on_bad_lines : {'error', 'warn', 'skip'} or callable, default 'error'\n"," Specifies what to do upon encountering a bad line (a line with too many fields).\n"," Allowed values are :\n","\n"," - 'error', raise an Exception when a bad line is encountered.\n"," - 'warn', raise a warning when a bad line is encountered and skip that line.\n"," - 'skip', skip bad lines without raising or warning when they are encountered.\n","\n"," .. versionadded:: 1.3.0\n","\n"," .. versionadded:: 1.4.0\n","\n"," - callable, function with signature\n"," ``(bad_line: list[str]) -> list[str] | None`` that will process a single\n"," bad line. ``bad_line`` is a list of strings split by the ``sep``.\n"," If the function returns ``None``, the bad line will be ignored.\n"," If the function returns a new list of strings with more elements than\n"," expected, a ``ParserWarning`` will be emitted while dropping extra elements.\n"," Only supported when ``engine=\"python\"``\n","\n","delim_whitespace : bool, default False\n"," Specifies whether or not whitespace (e.g. ``' '`` or ``' '``) will be\n"," used as the sep. Equivalent to setting ``sep='\\s+'``. If this option\n"," is set to True, nothing should be passed in for the ``delimiter``\n"," parameter.\n","low_memory : bool, default True\n"," Internally process the file in chunks, resulting in lower memory use\n"," while parsing, but possibly mixed type inference. To ensure no mixed\n"," types either set False, or specify the type with the `dtype` parameter.\n"," Note that the entire file is read into a single DataFrame regardless,\n"," use the `chunksize` or `iterator` parameter to return the data in chunks.\n"," (Only valid with C parser).\n","memory_map : bool, default False\n"," If a filepath is provided for `filepath_or_buffer`, map the file object\n"," directly onto memory and access the data directly from there. Using this\n"," option can improve performance because there is no longer any I/O overhead.\n","float_precision : str, optional\n"," Specifies which converter the C engine should use for floating-point\n"," values. The options are ``None`` or 'high' for the ordinary converter,\n"," 'legacy' for the original lower precision pandas converter, and\n"," 'round_trip' for the round-trip converter.\n","\n"," .. versionchanged:: 1.2\n","\n","storage_options : dict, optional\n"," Extra options that make sense for a particular storage connection, e.g.\n"," host, port, username, password, etc. For HTTP(S) URLs the key-value pairs\n"," are forwarded to ``urllib.request.Request`` as header options. For other\n"," URLs (e.g. starting with \"s3://\", and \"gcs://\") the key-value pairs are\n"," forwarded to ``fsspec.open``. Please see ``fsspec`` and ``urllib`` for more\n"," details, and for more examples on storage options refer `here\n"," `_.\n","\n"," .. versionadded:: 1.2\n","\n","dtype_backend : {\"numpy_nullable\", \"pyarrow\"}, defaults to NumPy backed DataFrames\n"," Which dtype_backend to use, e.g. whether a DataFrame should have NumPy\n"," arrays, nullable dtypes are used for all dtypes that have a nullable\n"," implementation when \"numpy_nullable\" is set, pyarrow is used for all\n"," dtypes if \"pyarrow\" is set.\n","\n"," The dtype_backends are still experimential.\n","\n"," .. versionadded:: 2.0\n","\n","Returns\n","-------\n","DataFrame or TextFileReader\n"," A comma-separated values (csv) file is returned as two-dimensional\n"," data structure with labeled axes.\n","\n","See Also\n","--------\n","DataFrame.to_csv : Write DataFrame to a comma-separated values (csv) file.\n","read_csv : Read a comma-separated values (csv) file into DataFrame.\n","read_fwf : Read a table of fixed-width formatted lines into DataFrame.\n","\n","Examples\n","--------\n",">>> pd.read_csv('data.csv') # doctest: +SKIP\n","\u001b[1;31mFile:\u001b[0m c:\\users\\mazo260d\\mambaforge\\envs\\devbio-napari-clone\\lib\\site-packages\\pandas\\io\\parsers\\readers.py\n","\u001b[1;31mType:\u001b[0m function"]}],"source":["pd.read_csv?"]},{"cell_type":"markdown","metadata":{"id":"Grd2NaYVqWxq"},"source":["### Selecting Columns, Rows and Creating Subsets\n","\n","We index DataFrames by columns, like this:"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":33,"status":"ok","timestamp":1692082105429,"user":{"displayName":"Martin Schätz","userId":"14609383414092679868"},"user_tz":-120},"id":"_TFm7-looBFF","outputId":"c1f70620-3e41-4dad-c802-fbc6df1df880"},"outputs":[{"data":{"text/plain":["0 1015.0\n","1 1129.0\n","2 333.0\n","3 515.0\n","4 624.0\n"," ... \n","16995 907.0\n","16996 1194.0\n","16997 1244.0\n","16998 1298.0\n","16999 806.0\n","Name: population, Length: 17000, dtype: float64"]},"execution_count":7,"metadata":{},"output_type":"execute_result"}],"source":["california_housing_dataframe['population']"]},{"cell_type":"markdown","metadata":{"id":"RQznmAMxqWxr"},"source":["We can get more columns by passing their names as a list. Furthermore, we can store this \"sub-dataframe\" in a new variable."]},{"cell_type":"code","execution_count":null,"metadata":{"id":"yj6i0n8IqWxr","outputId":"0a499f20-2da5-493f-81b5-684e4e0d6967"},"outputs":[{"data":{"text/html":["\n","\n","\n"," \n"," \n"," \n"," population\n"," households\n"," \n"," \n"," \n"," \n"," 0\n"," 1015.0\n"," 472.0\n"," \n"," \n"," 1\n"," 1129.0\n"," 463.0\n"," \n"," \n"," 2\n"," 333.0\n"," 117.0\n"," \n"," \n"," 3\n"," 515.0\n"," 226.0\n"," \n"," \n"," 4\n"," 624.0\n"," 262.0\n"," \n"," \n"," ...\n"," ...\n"," ...\n"," \n"," \n"," 16995\n"," 907.0\n"," 369.0\n"," \n"," \n"," 16996\n"," 1194.0\n"," 465.0\n"," \n"," \n"," 16997\n"," 1244.0\n"," 456.0\n"," \n"," \n"," 16998\n"," 1298.0\n"," 478.0\n"," \n"," \n"," 16999\n"," 806.0\n"," 270.0\n"," \n"," \n","\n","17000 rows × 2 columns\n",""],"text/plain":[" population households\n","0 1015.0 472.0\n","1 1129.0 463.0\n","2 333.0 117.0\n","3 515.0 226.0\n","4 624.0 262.0\n","... ... ...\n","16995 907.0 369.0\n","16996 1194.0 465.0\n","16997 1244.0 456.0\n","16998 1298.0 478.0\n","16999 806.0 270.0\n","\n","[17000 rows x 2 columns]"]},"execution_count":8,"metadata":{},"output_type":"execute_result"}],"source":["sub_dataframe = california_housing_dataframe[ ['population', 'households'] ]\n","sub_dataframe"]},{"cell_type":"markdown","metadata":{"id":"zAllPNZoqWxr"},"source":["If we want to get a single row, the proper way of doing that is to use the `.loc` method:"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"sPGI08UjqWxr","outputId":"4720aab4-977e-4dee-d8ce-ffb7d4216947"},"outputs":[{"data":{"text/plain":["population 333.0\n","households 117.0\n","Name: 2, dtype: float64"]},"execution_count":9,"metadata":{},"output_type":"execute_result"}],"source":["row_with_index_2 = california_housing_dataframe.loc[2, ['population', 'households'] ]\n","row_with_index_2"]},{"cell_type":"markdown","metadata":{"id":"65g1ZdGVjXsQ"},"source":["In addition, *pandas* provides an extremely rich API for advanced [indexing and selection](http://pandas.pydata.org/pandas-docs/stable/indexing.html) that is too extensive to be covered here."]},{"cell_type":"markdown","metadata":{"id":"mlJUQZPF0f9j"},"source":["## Saving data\n","\n","A `DataFrame` can be saved as a `.csv` file with the `.to_csv` method."]},{"cell_type":"code","execution_count":null,"metadata":{"id":"8FBvzKY92hNl"},"outputs":[],"source":["cities_dataframe.to_csv('cities_out.csv', index=False, sep=\";\")"]},{"cell_type":"markdown","metadata":{"id":"vMzGYfrdqWxs"},"source":["## Exercise\n","\n","From the following loaded CSV file, create a table that only contains these columns:\n","\n","- minor_axis_length\n","- major_axis_length\n","- aspect_ratio"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"6sZMc4OIqWxs","outputId":"c1f57523-1112-4941-ee67-cb626c6f928a"},"outputs":[{"data":{"text/html":["\n","\n","\n"," \n"," \n"," \n"," Unnamed: 0\n"," area\n"," mean_intensity\n"," minor_axis_length\n"," major_axis_length\n"," eccentricity\n"," extent\n"," feret_diameter_max\n"," equivalent_diameter_area\n"," bbox-0\n"," bbox-1\n"," bbox-2\n"," bbox-3\n"," \n"," \n"," \n"," \n"," 0\n"," 0\n"," 422\n"," 192.379147\n"," 16.488550\n"," 34.566789\n"," 0.878900\n"," 0.586111\n"," 35.227830\n"," 23.179885\n"," 0\n"," 11\n"," 30\n"," 35\n"," \n"," \n"," 1\n"," 1\n"," 182\n"," 180.131868\n"," 11.736074\n"," 20.802697\n"," 0.825665\n"," 0.787879\n"," 21.377558\n"," 15.222667\n"," 0\n"," 53\n"," 11\n"," 74\n"," \n"," \n"," 2\n"," 2\n"," 661\n"," 205.216339\n"," 28.409502\n"," 30.208433\n"," 0.339934\n"," 0.874339\n"," 32.756679\n"," 29.010538\n"," 0\n"," 95\n"," 28\n"," 122\n"," \n"," \n"," 3\n"," 3\n"," 437\n"," 216.585812\n"," 23.143996\n"," 24.606130\n"," 0.339576\n"," 0.826087\n"," 26.925824\n"," 23.588253\n"," 0\n"," 144\n"," 23\n"," 167\n"," \n"," \n"," 4\n"," 4\n"," 476\n"," 212.302521\n"," 19.852882\n"," 31.075106\n"," 0.769317\n"," 0.863884\n"," 31.384710\n"," 24.618327\n"," 0\n"," 237\n"," 29\n"," 256\n"," \n"," \n"," ...\n"," ...\n"," ...\n"," ...\n"," ...\n"," ...\n"," ...\n"," ...\n"," ...\n"," ...\n"," ...\n"," ...\n"," ...\n"," ...\n"," \n"," \n"," 56\n"," 56\n"," 211\n"," 185.061611\n"," 14.522762\n"," 18.489138\n"," 0.618893\n"," 0.781481\n"," 18.973666\n"," 16.390654\n"," 232\n"," 39\n"," 250\n"," 54\n"," \n"," \n"," 57\n"," 57\n"," 78\n"," 185.230769\n"," 6.028638\n"," 17.579799\n"," 0.939361\n"," 0.722222\n"," 18.027756\n"," 9.965575\n"," 248\n"," 170\n"," 254\n"," 188\n"," \n"," \n"," 58\n"," 58\n"," 86\n"," 183.720930\n"," 5.426871\n"," 21.261427\n"," 0.966876\n"," 0.781818\n"," 22.000000\n"," 10.464158\n"," 249\n"," 117\n"," 254\n"," 139\n"," \n"," \n"," 59\n"," 59\n"," 51\n"," 190.431373\n"," 5.032414\n"," 13.742079\n"," 0.930534\n"," 0.728571\n"," 14.035669\n"," 8.058239\n"," 249\n"," 228\n"," 254\n"," 242\n"," \n"," \n"," 60\n"," 60\n"," 46\n"," 175.304348\n"," 3.803982\n"," 15.948714\n"," 0.971139\n"," 0.766667\n"," 15.033296\n"," 7.653040\n"," 250\n"," 67\n"," 254\n"," 82\n"," \n"," \n","\n","61 rows × 13 columns\n",""],"text/plain":[" Unnamed: 0 area mean_intensity minor_axis_length major_axis_length \\\n","0 0 422 192.379147 16.488550 34.566789 \n","1 1 182 180.131868 11.736074 20.802697 \n","2 2 661 205.216339 28.409502 30.208433 \n","3 3 437 216.585812 23.143996 24.606130 \n","4 4 476 212.302521 19.852882 31.075106 \n",".. ... ... ... ... ... \n","56 56 211 185.061611 14.522762 18.489138 \n","57 57 78 185.230769 6.028638 17.579799 \n","58 58 86 183.720930 5.426871 21.261427 \n","59 59 51 190.431373 5.032414 13.742079 \n","60 60 46 175.304348 3.803982 15.948714 \n","\n"," eccentricity extent feret_diameter_max equivalent_diameter_area \\\n","0 0.878900 0.586111 35.227830 23.179885 \n","1 0.825665 0.787879 21.377558 15.222667 \n","2 0.339934 0.874339 32.756679 29.010538 \n","3 0.339576 0.826087 26.925824 23.588253 \n","4 0.769317 0.863884 31.384710 24.618327 \n",".. ... ... ... ... \n","56 0.618893 0.781481 18.973666 16.390654 \n","57 0.939361 0.722222 18.027756 9.965575 \n","58 0.966876 0.781818 22.000000 10.464158 \n","59 0.930534 0.728571 14.035669 8.058239 \n","60 0.971139 0.766667 15.033296 7.653040 \n","\n"," bbox-0 bbox-1 bbox-2 bbox-3 \n","0 0 11 30 35 \n","1 0 53 11 74 \n","2 0 95 28 122 \n","3 0 144 23 167 \n","4 0 237 29 256 \n",".. ... ... ... ... \n","56 232 39 250 54 \n","57 248 170 254 188 \n","58 249 117 254 139 \n","59 249 228 254 242 \n","60 250 67 254 82 \n","\n","[61 rows x 13 columns]"]},"execution_count":16,"metadata":{},"output_type":"execute_result"}],"source":["blobs_df = pd.read_csv(\"https://github.com/vmcf-konfmi/MB100T01/raw/main/data/blobs_statistics.csv\")\n","#blobs_df = pd.read_csv('../../data/blobs_statistics.csv')\n","blobs_df"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"szFi0ubfqWxt"},"outputs":[],"source":[]},{"cell_type":"markdown","metadata":{"id":"fH1zusN7GKCx"},"source":["**Watermark**"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":1101,"status":"ok","timestamp":1692082106984,"user":{"displayName":"Martin Schätz","userId":"14609383414092679868"},"user_tz":-120},"id":"iH1jL0baGMJW","outputId":"9ebd0898-beb7-4576-d35a-64350d8c3395"},"outputs":[{"name":"stdout","output_type":"stream","text":["Last updated: 2023-08-24T14:24:06.278180+02:00\n","\n","Python implementation: CPython\n","Python version : 3.9.17\n","IPython version : 8.14.0\n","\n","Compiler : MSC v.1929 64 bit (AMD64)\n","OS : Windows\n","Release : 10\n","Machine : AMD64\n","Processor : Intel64 Family 6 Model 165 Stepping 2, GenuineIntel\n","CPU cores : 16\n","Architecture: 64bit\n","\n"]},{"name":"stdout","output_type":"stream","text":["watermark : 2.4.3\n","numpy : 1.23.5\n","pandas : 2.0.3\n","seaborn : 0.12.2\n","pivottablejs: 0.9.0\n","\n"]}],"source":["from watermark import watermark\n","watermark(iversions=True, globals_=globals())\n","print(watermark())\n","print(watermark(packages=\"watermark,numpy,pandas,seaborn,pivottablejs\"))"]}],"metadata":{"colab":{"provenance":[]},"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.17"}},"nbformat":4,"nbformat_minor":0}
17000 rows × 2 columns
61 rows × 13 columns