{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "\n", "data = pd.read_csv('Datasets/Machine Learning/Birds/All_Invasive_Birds.csv')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Common name\n", "Mute Swan 117831\n", "Pheasant 92462\n", "Canada Goose 50344\n", "Rock Dove 31449\n", "Red-legged Partridge 22395\n", " ... \n", "Red-headed Bunting 1\n", "Pallas's Rosefinch 1\n", "Ross's Goose 1\n", "Black Kite 1\n", "Redhead 1\n", "Length: 87, dtype: int64" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Returns pandas Series datatype\n", "birds = data.value_counts('Common name')\n", "top_birds_list = birds[0:20].index.to_list()\n", "birds" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "# For each bird on the list, retrieve all rows with their corresponding common name \n", "# as a separate dataframe and export dataframe to csv file\n", "\n", "PATH = 'Datasets/Machine Learning/Birds/'\n", "for bird in top_birds_list:\n", " data.loc[data['Common name'] == bird].to_csv(PATH+bird.replace(' ','_')+'.csv')\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.13 ('env': venv)", "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 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)]" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "f025c48a9b67ab76bdc0400dfa0f9ba99120976b4a6ec6a63d1c946516165c91" } } }, "nbformat": 4, "nbformat_minor": 2 }