{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Fix \"-\" in \"Collected_by\" Columns in full_master and Heliconius subsets\n", "\n", "See [discussion](https://huggingface.co./datasets/imageomics/Heliconius-Collection_Cambridge-Butterfly/discussions/7). I then tested each column that showed up as \"null\" in type on the dataset viewer (searching for df[col] == \"-\")." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# while main is commit 3264ec40dbc9db025e027ddb2abca0914cd6500f\n", "df = pd.read_csv(\"https://huggingface.co./datasets/imageomics/Heliconius-Collection_Cambridge-Butterfly/resolve/main/img_master.csv\", low_memory= False)\n", "df_heli = pd.read_csv(\"https://huggingface.co./datasets/imageomics/Heliconius-Collection_Cambridge-Butterfly/resolve/main/Heliconius_img_master.csv\", low_memory=False)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "column Collected_by has 62 instances of '-'\n" ] } ], "source": [ "for col in list(df.columns):\n", " temp = df.loc[df[col] == \"-\"]\n", " if temp.shape[0] > 0:\n", " print(f\"column {col} has {temp.shape[0]} instances of '-'\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "column Collected_by has 62 instances of '-'\n" ] } ], "source": [ "for col in list(df_heli.columns):\n", " temp = df_heli.loc[df_heli[col] == \"-\"]\n", " if temp.shape[0] > 0:\n", " print(f\"column {col} has {temp.shape[0]} instances of '-'\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Looks like we just need to fix the `Collected_by` column for both CSVs. We'll replace these with `null` so that it doesn't break the dataset viewer." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "df.loc[df[\"Collected_by\"] == \"-\", \"Collected_by\"] = np.nan\n", "df_heli.loc[df_heli[\"Collected_by\"] == \"-\", \"Collected_by\"] = np.nan" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Now let's save the fix" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "df.to_csv(\"../img_master.csv\", index = False)\n", "df_heli.to_csv(\"../Heliconius_img_master.csv\", index = False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "std", "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.11.3" } }, "nbformat": 4, "nbformat_minor": 2 }