Skip to content

Commit bb95c88

Browse files
authored
Data Serialization & Date time, Creating csv file
Using Jupyter Notebook
1 parent 4a289bf commit bb95c88

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

Data_Serialize.ipynb

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "1531083e-8ff4-4ef7-a124-f032c434860b",
6+
"metadata": {},
7+
"source": [
8+
"### Data Serialization"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 1,
14+
"id": "a03e5944-5059-4447-b759-95f770012c43",
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"{\"name\": \"Sunil\", \"age\": 41}\n",
22+
"<class 'str'>\n",
23+
"{'name': 'Sunil', 'age': 41}\n",
24+
"<class 'dict'>\n"
25+
]
26+
}
27+
],
28+
"source": [
29+
"import json \n",
30+
"data ={'name':'Sunil','age':41}\n",
31+
"\n",
32+
"json_str =json.dumps(data)\n",
33+
"print(json_str)\n",
34+
"print(type(json_str))\n",
35+
"\n",
36+
"parsed_data=json.loads(json_str)\n",
37+
"print(parsed_data)\n",
38+
"print(type(parsed_data))"
39+
]
40+
},
41+
{
42+
"cell_type": "markdown",
43+
"id": "bf26772b-5825-4941-b8f1-27932aaea45e",
44+
"metadata": {},
45+
"source": [
46+
"## Creating CSV file"
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": 2,
52+
"id": "d00bba44-83cc-4e3d-b19c-cfc06d17e00f",
53+
"metadata": {},
54+
"outputs": [
55+
{
56+
"name": "stdout",
57+
"output_type": "stream",
58+
"text": [
59+
"['name', 'age']\n",
60+
"['SUNIL', '41']\n"
61+
]
62+
}
63+
],
64+
"source": [
65+
"import csv\n",
66+
"with open('example.csv',mode='w',newline='') as file:\n",
67+
" writer=csv.writer(file)\n",
68+
" writer.writerow(['name','age'])\n",
69+
" writer.writerow(['SUNIL',41])\n",
70+
"\n",
71+
"with open('example.csv',mode='r') as file:\n",
72+
" reader = csv.reader(file)\n",
73+
" for row in reader:\n",
74+
" print(row)"
75+
]
76+
},
77+
{
78+
"cell_type": "markdown",
79+
"id": "e66d81a6-dc2f-4303-ab32-c58167e8db67",
80+
"metadata": {},
81+
"source": [
82+
"### Import Datetime and timedelta"
83+
]
84+
},
85+
{
86+
"cell_type": "code",
87+
"execution_count": 3,
88+
"id": "61bc3cc1-a23f-4d04-a9fa-1b72563bd70a",
89+
"metadata": {},
90+
"outputs": [
91+
{
92+
"name": "stdout",
93+
"output_type": "stream",
94+
"text": [
95+
"2025-03-09 11:46:56.233616\n",
96+
"2025-03-08 11:46:56.233616\n"
97+
]
98+
}
99+
],
100+
"source": [
101+
"from datetime import datetime,timedelta\n",
102+
"\n",
103+
"now=datetime.now()\n",
104+
"print(now)\n",
105+
"\n",
106+
"yesterday=now-timedelta(days=1)\n",
107+
"print(yesterday)"
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": null,
113+
"id": "a765c01d-d970-4c9a-ba00-70bd8ae09bb6",
114+
"metadata": {},
115+
"outputs": [
116+
{
117+
"name": "stdout",
118+
"output_type": "stream",
119+
"text": [
120+
"1741501043.1172035\n"
121+
]
122+
}
123+
],
124+
"source": [
125+
"## time\n",
126+
"import time\n",
127+
"print(time.time())\n",
128+
"time.sleep(4)\n",
129+
"print(time.time())"
130+
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": null,
135+
"id": "637d965b-f8c9-43ae-b22e-4168d8cb9686",
136+
"metadata": {},
137+
"outputs": [],
138+
"source": []
139+
}
140+
],
141+
"metadata": {
142+
"kernelspec": {
143+
"display_name": "Python 3 (ipykernel)",
144+
"language": "python",
145+
"name": "python3"
146+
},
147+
"language_info": {
148+
"codemirror_mode": {
149+
"name": "ipython",
150+
"version": 3
151+
},
152+
"file_extension": ".py",
153+
"mimetype": "text/x-python",
154+
"name": "python",
155+
"nbconvert_exporter": "python",
156+
"pygments_lexer": "ipython3",
157+
"version": "3.12.7"
158+
}
159+
},
160+
"nbformat": 4,
161+
"nbformat_minor": 5
162+
}

0 commit comments

Comments
 (0)