File size: 3,434 Bytes
8922683
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
{
 "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
}