add pickle dict

This commit is contained in:
SKYLIGHTSUFA
2024-03-29 09:54:44 +03:00
parent 6102ce37c2
commit 76fc06abee
2 changed files with 19 additions and 5 deletions

View File

@@ -58,28 +58,42 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 59, "execution_count": 62,
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"C:\\Users\\fatik\\AppData\\Local\\Temp\\ipykernel_12208\\551298004.py:3: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n", "C:\\Users\\fatik\\AppData\\Local\\Temp\\ipykernel_12208\\3238385593.py:3: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
" dicter[x.id] = x[1]\n" " dicter[x.id] = x[1]\n"
] ]
},
{
"data": {
"text/plain": "'Стефен Ананикз'"
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
} }
], ],
"source": [ "source": [
"dicter = {}\n", "dicter = {}\n",
"def get_dict(x):\n", "def get_dict(x):\n",
" dicter[x.id] = x[1]\n", " dicter[x.id] = x[1]\n",
"data[\"json\"] = data.apply(lambda x: get_dict(x), axis=1)" "data[\"json\"] = data.apply(lambda x: get_dict(x), axis=1)\n",
"import pickle\n",
"\n",
"with open('saved_dictionary.pkl', 'wb') as f:\n",
" pickle.dump(dicter, f)\n",
"with open('saved_dictionary.pkl', 'rb') as f:\n",
" loaded_dict = pickle.load(f)"
], ],
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-03-29T06:52:14.631001800Z", "end_time": "2024-03-29T06:54:05.064292600Z",
"start_time": "2024-03-29T06:52:14.473163900Z" "start_time": "2024-03-29T06:54:04.924879400Z"
} }
} }
}, },

Binary file not shown.