egrace479 commited on
Commit
d65770f
1 Parent(s): 03f93bf

Notebook finding and fixing the '-' in 'Collected_by' column of full and heliconius CSVs

Browse files
Files changed (1) hide show
  1. notebooks/Data-gen-1-4.ipynb +136 -0
notebooks/Data-gen-1-4.ipynb ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import pandas as pd\n",
10
+ "import numpy as np"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "markdown",
15
+ "metadata": {},
16
+ "source": [
17
+ "# Fix \"-\" in \"Collected_by\" Columns in full_master and Heliconius subsets\n",
18
+ "\n",
19
+ "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] == \"-\")."
20
+ ]
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "execution_count": 2,
25
+ "metadata": {},
26
+ "outputs": [],
27
+ "source": [
28
+ "# while main is commit 3264ec40dbc9db025e027ddb2abca0914cd6500f\n",
29
+ "df = pd.read_csv(\"https://huggingface.co/datasets/imageomics/Heliconius-Collection_Cambridge-Butterfly/resolve/main/img_master.csv\", low_memory= False)\n",
30
+ "df_heli = pd.read_csv(\"https://huggingface.co/datasets/imageomics/Heliconius-Collection_Cambridge-Butterfly/resolve/main/Heliconius_img_master.csv\", low_memory=False)"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": 3,
36
+ "metadata": {},
37
+ "outputs": [
38
+ {
39
+ "name": "stdout",
40
+ "output_type": "stream",
41
+ "text": [
42
+ "column Collected_by has 62 instances of '-'\n"
43
+ ]
44
+ }
45
+ ],
46
+ "source": [
47
+ "for col in list(df.columns):\n",
48
+ " temp = df.loc[df[col] == \"-\"]\n",
49
+ " if temp.shape[0] > 0:\n",
50
+ " print(f\"column {col} has {temp.shape[0]} instances of '-'\")"
51
+ ]
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": 4,
56
+ "metadata": {},
57
+ "outputs": [
58
+ {
59
+ "name": "stdout",
60
+ "output_type": "stream",
61
+ "text": [
62
+ "column Collected_by has 62 instances of '-'\n"
63
+ ]
64
+ }
65
+ ],
66
+ "source": [
67
+ "for col in list(df_heli.columns):\n",
68
+ " temp = df_heli.loc[df_heli[col] == \"-\"]\n",
69
+ " if temp.shape[0] > 0:\n",
70
+ " print(f\"column {col} has {temp.shape[0]} instances of '-'\")"
71
+ ]
72
+ },
73
+ {
74
+ "cell_type": "markdown",
75
+ "metadata": {},
76
+ "source": [
77
+ "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."
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "execution_count": 5,
83
+ "metadata": {},
84
+ "outputs": [],
85
+ "source": [
86
+ "df.loc[df[\"Collected_by\"] == \"-\", \"Collected_by\"] = np.nan\n",
87
+ "df_heli.loc[df_heli[\"Collected_by\"] == \"-\", \"Collected_by\"] = np.nan"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "markdown",
92
+ "metadata": {},
93
+ "source": [
94
+ "## Now let's save the fix"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": 6,
100
+ "metadata": {},
101
+ "outputs": [],
102
+ "source": [
103
+ "df.to_csv(\"../img_master.csv\", index = False)\n",
104
+ "df_heli.to_csv(\"../Heliconius_img_master.csv\", index = False)"
105
+ ]
106
+ },
107
+ {
108
+ "cell_type": "code",
109
+ "execution_count": null,
110
+ "metadata": {},
111
+ "outputs": [],
112
+ "source": []
113
+ }
114
+ ],
115
+ "metadata": {
116
+ "kernelspec": {
117
+ "display_name": "std",
118
+ "language": "python",
119
+ "name": "python3"
120
+ },
121
+ "language_info": {
122
+ "codemirror_mode": {
123
+ "name": "ipython",
124
+ "version": 3
125
+ },
126
+ "file_extension": ".py",
127
+ "mimetype": "text/x-python",
128
+ "name": "python",
129
+ "nbconvert_exporter": "python",
130
+ "pygments_lexer": "ipython3",
131
+ "version": "3.11.3"
132
+ }
133
+ },
134
+ "nbformat": 4,
135
+ "nbformat_minor": 2
136
+ }