File size: 12,611 Bytes
7182eb1
 
 
 
 
 
 
 
2c7b8b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7182eb1
 
 
2c7b8b6
 
 
7182eb1
 
 
 
2c7b8b6
7182eb1
 
2c7b8b6
7182eb1
2c7b8b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7182eb1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>spoat</th>\n",
       "      <th>ecorregion</th>\n",
       "      <th>sag</th>\n",
       "      <th>provincia</th>\n",
       "      <th>supha</th>\n",
       "      <th>area</th>\n",
       "      <th>departamento</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Monte ribereno, talares orientales y bahia de ...</td>\n",
       "      <td>Pampa</td>\n",
       "      <td>ARBA - Gerencia de Servicios Catastrales</td>\n",
       "      <td>BUENOS AIRES</td>\n",
       "      <td>977451.943</td>\n",
       "      <td>977452</td>\n",
       "      <td>Magdalena</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Sudoeste de Buenos Aires</td>\n",
       "      <td>Espinal</td>\n",
       "      <td>ARBA - Gerencia de Servicios Catastrales</td>\n",
       "      <td>BUENOS AIRES</td>\n",
       "      <td>2357878.315</td>\n",
       "      <td>2357877</td>\n",
       "      <td>Patagones</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Delta del rio Parana</td>\n",
       "      <td>Delta e islas del rio Parana</td>\n",
       "      <td>ARBA - Gerencia de Servicios Catastrales</td>\n",
       "      <td>BUENOS AIRES</td>\n",
       "      <td>202074.295</td>\n",
       "      <td>202074</td>\n",
       "      <td>Campana</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Hornocal - Valle Grande</td>\n",
       "      <td>Puna/Selva de las Yungas</td>\n",
       "      <td>Direc. Grl. de Inmuebles</td>\n",
       "      <td>JUJUY</td>\n",
       "      <td>287358.817</td>\n",
       "      <td>287359</td>\n",
       "      <td>Valle Gran</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Susques - Jama - Catua - Olaroz</td>\n",
       "      <td>Puna/Altos Andes</td>\n",
       "      <td>Direc. Grl. de Inmuebles</td>\n",
       "      <td>JUJUY</td>\n",
       "      <td>268648.734</td>\n",
       "      <td>268649</td>\n",
       "      <td>Susques</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Piedemonte Andino del Area Metropolitana de Me...</td>\n",
       "      <td>Altos Andes/Monte de Llanuras y Mesetas/Monte ...</td>\n",
       "      <td>IDE Mendoza</td>\n",
       "      <td>MENDOZA</td>\n",
       "      <td>31905.735</td>\n",
       "      <td>31906</td>\n",
       "      <td>Capital</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Piedemonte del Valle de Uco</td>\n",
       "      <td>Altos Andes/Monte de Llanuras y Mesetas/Estepa...</td>\n",
       "      <td>IDE Mendoza</td>\n",
       "      <td>MENDOZA</td>\n",
       "      <td>48565.495</td>\n",
       "      <td>48565</td>\n",
       "      <td>Tupungato</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Oasis Norte - Cinturon Verde</td>\n",
       "      <td>Monte de Llanuras y Mesetas</td>\n",
       "      <td>IDE Mendoza</td>\n",
       "      <td>MENDOZA</td>\n",
       "      <td>71719.634</td>\n",
       "      <td>71720</td>\n",
       "      <td>GuaymallÃ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Laguna Llancanelo - Cuenca del Rio Malargue</td>\n",
       "      <td>Altos Andes/Estepa Patagonica</td>\n",
       "      <td>IDE Mendoza</td>\n",
       "      <td>MENDOZA</td>\n",
       "      <td>54999.000</td>\n",
       "      <td>54999</td>\n",
       "      <td>Malargï</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               spoat  \\\n",
       "0  Monte ribereno, talares orientales y bahia de ...   \n",
       "1                           Sudoeste de Buenos Aires   \n",
       "2                               Delta del rio Parana   \n",
       "3                            Hornocal - Valle Grande   \n",
       "4                    Susques - Jama - Catua - Olaroz   \n",
       "5  Piedemonte Andino del Area Metropolitana de Me...   \n",
       "6                        Piedemonte del Valle de Uco   \n",
       "7                       Oasis Norte - Cinturon Verde   \n",
       "8        Laguna Llancanelo - Cuenca del Rio Malargue   \n",
       "\n",
       "                                          ecorregion  \\\n",
       "0                                              Pampa   \n",
       "1                                            Espinal   \n",
       "2                       Delta e islas del rio Parana   \n",
       "3                           Puna/Selva de las Yungas   \n",
       "4                                   Puna/Altos Andes   \n",
       "5  Altos Andes/Monte de Llanuras y Mesetas/Monte ...   \n",
       "6  Altos Andes/Monte de Llanuras y Mesetas/Estepa...   \n",
       "7                        Monte de Llanuras y Mesetas   \n",
       "8                      Altos Andes/Estepa Patagonica   \n",
       "\n",
       "                                        sag     provincia        supha  \\\n",
       "0  ARBA - Gerencia de Servicios Catastrales  BUENOS AIRES   977451.943   \n",
       "1  ARBA - Gerencia de Servicios Catastrales  BUENOS AIRES  2357878.315   \n",
       "2  ARBA - Gerencia de Servicios Catastrales  BUENOS AIRES   202074.295   \n",
       "3                  Direc. Grl. de Inmuebles         JUJUY   287358.817   \n",
       "4                  Direc. Grl. de Inmuebles         JUJUY   268648.734   \n",
       "5                               IDE Mendoza       MENDOZA    31905.735   \n",
       "6                               IDE Mendoza       MENDOZA    48565.495   \n",
       "7                               IDE Mendoza       MENDOZA    71719.634   \n",
       "8                               IDE Mendoza       MENDOZA    54999.000   \n",
       "\n",
       "      area departamento  \n",
       "0   977452    Magdalena  \n",
       "1  2357877    Patagones  \n",
       "2   202074      Campana  \n",
       "3   287359   Valle Gran  \n",
       "4   268649      Susques  \n",
       "5    31906      Capital  \n",
       "6    48565    Tupungato  \n",
       "7    71720    Guaymallà \n",
       "8    54999     Malargï  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import sqlite3\n",
    "\n",
    "conn = sqlite3.connect('sitios2.sqlite')\n",
    "df = pd.read_sql_query(\"SELECT spoat, ecorregion, sag, provincia, supha, area, departamento FROM sitiospilotojson\", conn)\n",
    "conn.close()\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "dictionary update sequence element #0 has length 4; 2 is required",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[2], line 8\u001b[0m\n\u001b[0;32m      4\u001b[0m file_to_read \u001b[39m=\u001b[39m \u001b[39mopen\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39mD:/hugging/Agent/streamlit_agent/runs/alanis.pickle\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mrb\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m      6\u001b[0m loaded_dictionary \u001b[39m=\u001b[39m pickle\u001b[39m.\u001b[39mload(file_to_read)\n\u001b[1;32m----> 8\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mdict\u001b[39;49m(loaded_dictionary))\n\u001b[0;32m      9\u001b[0m \u001b[39m# person1 = {\"name\": \"Marcus King\", \"Age\": \"22\", \"Profession\" : \"Author\"}\u001b[39;00m\n\u001b[0;32m     10\u001b[0m \n\u001b[0;32m     11\u001b[0m \u001b[39m# pickle.dump(person1, open(\"person1.p\", \"wb\"))\u001b[39;00m\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m     15\u001b[0m \u001b[39m# # obj = pd.read_pickle(open(\"D:/hugging/Agent/streamlit_agent/runs/alanis.pickle\",\"rb\"))\u001b[39;00m\n\u001b[0;32m     16\u001b[0m \u001b[39m# print(obj)\u001b[39;00m\n",
      "\u001b[1;31mValueError\u001b[0m: dictionary update sequence element #0 has length 4; 2 is required"
     ]
    }
   ],
   "source": [
    "import pickle\n",
    "import pandas as pd\n",
    "\n",
    "file_to_read = open(\"D:/hugging/Agent/streamlit_agent/runs/alanis.pickle\", \"rb\")\n",
    "\n",
    "loaded_dictionary = pickle.load(file_to_read)\n",
    "\n",
    "print(dict(loaded_dictionary))\n",
    "# person1 = {\"name\": \"Marcus King\", \"Age\": \"22\", \"Profession\" : \"Author\"}\n",
    "\n",
    "# pickle.dump(person1, open(\"person1.p\", \"wb\"))\n",
    "# file = open(\"D:/hugging/Agent/streamlit_agent/runs/alanis.pickle\",\"rb\")\n",
    "# obj = pickle.load(file, fix_imports = True, encoding = 'ASCII', errors = 'strict')\n",
    "# # obj = pickle.load(open(\"D:/hugging/Agent/streamlit_agent/runs/alanis.pickle\",\"rb\"))\n",
    "# # obj = pd.read_pickle(open(\"D:/hugging/Agent/streamlit_agent/runs/alanis.pickle\",\"rb\"))\n",
    "# print(obj)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import shelve\n",
    "filename = \"D:/hugging/Agent/streamlit_agent/runs/alanis\"\n",
    "d = shelve.open(filename) # open -- file may get suffix added by low-level\n",
    "                          # library\n",
    "                          \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<shelve.DbfilenameShelf object at 0x000001F51BA9F710> []\n"
     ]
    }
   ],
   "source": [
    "print(d,list(d.values()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "d[key] = data   # store data at key (overwrites old data if\n",
    "                # using an existing key)\n",
    "data = d[key]   # retrieve a COPY of data at key (raise KeyError if no\n",
    "                # such key)\n",
    "del d[key]      # delete data stored at key (raises KeyError\n",
    "                # if no such key)\n",
    "flag = key in d        # true if the key exists\n",
    "klist = list(d.keys()) # a list of all existing keys (slow!)\n",
    "\n",
    "# as d was opened WITHOUT writeback=True, beware:\n",
    "d['xx'] = [0, 1, 2]    # this works as expected, but...\n",
    "d['xx'].append(3)      # *this doesn't!* -- d['xx'] is STILL [0, 1, 2]!\n",
    "\n",
    "# having opened d without writeback=True, you need to code carefully:\n",
    "temp = d['xx']      # extracts the copy\n",
    "temp.append(5)      # mutates the copy\n",
    "d['xx'] = temp      # stores the copy right back, to persist it\n",
    "\n",
    "# or, d=shelve.open(filename,writeback=True) would let you just code\n",
    "# d['xx'].append(5) and have it work as expected, BUT it would also\n",
    "# consume more memory and make the d.close() operation slower.\n",
    "\n",
    "d.close()       # close it"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.4"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}