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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 7,
|
6 |
+
"id": "985f02de",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"data": {
|
11 |
+
"text/html": [
|
12 |
+
"<div>\n",
|
13 |
+
"<style scoped>\n",
|
14 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
15 |
+
" vertical-align: middle;\n",
|
16 |
+
" }\n",
|
17 |
+
"\n",
|
18 |
+
" .dataframe tbody tr th {\n",
|
19 |
+
" vertical-align: top;\n",
|
20 |
+
" }\n",
|
21 |
+
"\n",
|
22 |
+
" .dataframe thead th {\n",
|
23 |
+
" text-align: right;\n",
|
24 |
+
" }\n",
|
25 |
+
"</style>\n",
|
26 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
27 |
+
" <thead>\n",
|
28 |
+
" <tr style=\"text-align: right;\">\n",
|
29 |
+
" <th></th>\n",
|
30 |
+
" <th>Employee Name</th>\n",
|
31 |
+
" <th>Age</th>\n",
|
32 |
+
" <th>Department</th>\n",
|
33 |
+
" <th>Salary</th>\n",
|
34 |
+
" </tr>\n",
|
35 |
+
" </thead>\n",
|
36 |
+
" <tbody>\n",
|
37 |
+
" <tr>\n",
|
38 |
+
" <th>0</th>\n",
|
39 |
+
" <td>John</td>\n",
|
40 |
+
" <td>31</td>\n",
|
41 |
+
" <td>HR</td>\n",
|
42 |
+
" <td>108189</td>\n",
|
43 |
+
" </tr>\n",
|
44 |
+
" <tr>\n",
|
45 |
+
" <th>1</th>\n",
|
46 |
+
" <td>Alice</td>\n",
|
47 |
+
" <td>39</td>\n",
|
48 |
+
" <td>Engineering</td>\n",
|
49 |
+
" <td>100371</td>\n",
|
50 |
+
" </tr>\n",
|
51 |
+
" <tr>\n",
|
52 |
+
" <th>2</th>\n",
|
53 |
+
" <td>Bob</td>\n",
|
54 |
+
" <td>52</td>\n",
|
55 |
+
" <td>Marketing</td>\n",
|
56 |
+
" <td>90333</td>\n",
|
57 |
+
" </tr>\n",
|
58 |
+
" <tr>\n",
|
59 |
+
" <th>3</th>\n",
|
60 |
+
" <td>Carol</td>\n",
|
61 |
+
" <td>29</td>\n",
|
62 |
+
" <td>Sales</td>\n",
|
63 |
+
" <td>69356</td>\n",
|
64 |
+
" </tr>\n",
|
65 |
+
" <tr>\n",
|
66 |
+
" <th>4</th>\n",
|
67 |
+
" <td>David</td>\n",
|
68 |
+
" <td>25</td>\n",
|
69 |
+
" <td>Finance</td>\n",
|
70 |
+
" <td>79835</td>\n",
|
71 |
+
" </tr>\n",
|
72 |
+
" </tbody>\n",
|
73 |
+
"</table>\n",
|
74 |
+
"</div>"
|
75 |
+
],
|
76 |
+
"text/plain": [
|
77 |
+
" Employee Name Age Department Salary\n",
|
78 |
+
"0 John 31 HR 108189\n",
|
79 |
+
"1 Alice 39 Engineering 100371\n",
|
80 |
+
"2 Bob 52 Marketing 90333\n",
|
81 |
+
"3 Carol 29 Sales 69356\n",
|
82 |
+
"4 David 25 Finance 79835"
|
83 |
+
]
|
84 |
+
},
|
85 |
+
"execution_count": 7,
|
86 |
+
"metadata": {},
|
87 |
+
"output_type": "execute_result"
|
88 |
+
}
|
89 |
+
],
|
90 |
+
"source": [
|
91 |
+
"import pandas as pd\n",
|
92 |
+
"import random\n",
|
93 |
+
"import numpy as np\n",
|
94 |
+
"\n",
|
95 |
+
"# Create random data\n",
|
96 |
+
"data = {\n",
|
97 |
+
" 'Employee Name': ['John', 'Alice', 'Bob', 'Carol', 'David'],\n",
|
98 |
+
" 'Age': [random.randint(22, 55) for _ in range(5)],\n",
|
99 |
+
" 'Department': ['HR', 'Engineering', 'Marketing', 'Sales', 'Finance'],\n",
|
100 |
+
" 'Salary': [random.randint(50000, 120000) for _ in range(5)]\n",
|
101 |
+
"}\n",
|
102 |
+
"\n",
|
103 |
+
"# Convert to DataFrame\n",
|
104 |
+
"df = pd.DataFrame(data)\n",
|
105 |
+
"\n",
|
106 |
+
"# Save to Excel\n",
|
107 |
+
"df.to_excel('employee_data.xlsx', index=False)\n",
|
108 |
+
"\n",
|
109 |
+
"# Save to CSV\n",
|
110 |
+
"df.to_csv('employee_data.csv', index=False)\n",
|
111 |
+
"\n",
|
112 |
+
"# Display the created DataFrame\n",
|
113 |
+
"df\n"
|
114 |
+
]
|
115 |
+
},
|
116 |
+
{
|
117 |
+
"cell_type": "code",
|
118 |
+
"execution_count": 4,
|
119 |
+
"id": "e6b3ffce",
|
120 |
+
"metadata": {},
|
121 |
+
"outputs": [
|
122 |
+
{
|
123 |
+
"name": "stdout",
|
124 |
+
"output_type": "stream",
|
125 |
+
"text": [
|
126 |
+
"Excel Data:\n",
|
127 |
+
" Employee Name Age Department Salary\n",
|
128 |
+
"0 John 45 HR 68212\n",
|
129 |
+
"1 Alice 26 Engineering 84012\n",
|
130 |
+
"2 Bob 39 Marketing 111842\n",
|
131 |
+
"3 Carol 31 Sales 96286\n",
|
132 |
+
"4 David 52 Finance 115640\n"
|
133 |
+
]
|
134 |
+
}
|
135 |
+
],
|
136 |
+
"source": [
|
137 |
+
"# Reading the Excel file\n",
|
138 |
+
"df_excel = pd.read_excel('employee_data.xlsx')\n",
|
139 |
+
"\n",
|
140 |
+
"# Display the DataFrame\n",
|
141 |
+
"print(\"Excel Data:\")\n",
|
142 |
+
"print(df_excel)\n"
|
143 |
+
]
|
144 |
+
},
|
145 |
+
{
|
146 |
+
"cell_type": "code",
|
147 |
+
"execution_count": 5,
|
148 |
+
"id": "5c83abd8",
|
149 |
+
"metadata": {},
|
150 |
+
"outputs": [
|
151 |
+
{
|
152 |
+
"name": "stdout",
|
153 |
+
"output_type": "stream",
|
154 |
+
"text": [
|
155 |
+
"CSV Data:\n",
|
156 |
+
" Employee Name Age Department Salary\n",
|
157 |
+
"0 John 45 HR 68212\n",
|
158 |
+
"1 Alice 26 Engineering 84012\n",
|
159 |
+
"2 Bob 39 Marketing 111842\n",
|
160 |
+
"3 Carol 31 Sales 96286\n",
|
161 |
+
"4 David 52 Finance 115640\n"
|
162 |
+
]
|
163 |
+
}
|
164 |
+
],
|
165 |
+
"source": [
|
166 |
+
"# Reading the CSV file\n",
|
167 |
+
"df_csv = pd.read_csv('employee_data.csv')\n",
|
168 |
+
"\n",
|
169 |
+
"# Display the DataFrame\n",
|
170 |
+
"print(\"CSV Data:\")\n",
|
171 |
+
"print(df_csv)\n"
|
172 |
+
]
|
173 |
+
},
|
174 |
+
{
|
175 |
+
"cell_type": "code",
|
176 |
+
"execution_count": 6,
|
177 |
+
"id": "fe7dc33a",
|
178 |
+
"metadata": {},
|
179 |
+
"outputs": [
|
180 |
+
{
|
181 |
+
"name": "stdout",
|
182 |
+
"output_type": "stream",
|
183 |
+
"text": [
|
184 |
+
"Excel Data Loaded Successfully\n",
|
185 |
+
" Employee Name Age Department Salary\n",
|
186 |
+
"0 John 45 HR 68212\n",
|
187 |
+
"1 Alice 26 Engineering 84012\n",
|
188 |
+
"2 Bob 39 Marketing 111842\n",
|
189 |
+
"3 Carol 31 Sales 96286\n",
|
190 |
+
"4 David 52 Finance 115640\n",
|
191 |
+
"CSV Data Loaded Successfully\n",
|
192 |
+
" Employee Name Age Department Salary\n",
|
193 |
+
"0 John 45 HR 68212\n",
|
194 |
+
"1 Alice 26 Engineering 84012\n",
|
195 |
+
"2 Bob 39 Marketing 111842\n",
|
196 |
+
"3 Carol 31 Sales 96286\n",
|
197 |
+
"4 David 52 Finance 115640\n"
|
198 |
+
]
|
199 |
+
}
|
200 |
+
],
|
201 |
+
"source": [
|
202 |
+
"# Try reading the Excel file\n",
|
203 |
+
"try:\n",
|
204 |
+
" df_excel = pd.read_excel('employee_data.xlsx')\n",
|
205 |
+
" print(\"Excel Data Loaded Successfully\")\n",
|
206 |
+
" print(df_excel)\n",
|
207 |
+
"except FileNotFoundError:\n",
|
208 |
+
" print(\"Error: Excel file not found!\")\n",
|
209 |
+
"except Exception as e:\n",
|
210 |
+
" print(f\"Error loading Excel file: {e}\")\n",
|
211 |
+
"\n",
|
212 |
+
"# Try reading the CSV file\n",
|
213 |
+
"try:\n",
|
214 |
+
" df_csv = pd.read_csv('employee_data.csv')\n",
|
215 |
+
" print(\"CSV Data Loaded Successfully\")\n",
|
216 |
+
" print(df_csv)\n",
|
217 |
+
"except FileNotFoundError:\n",
|
218 |
+
" print(\"Error: CSV file not found!\")\n",
|
219 |
+
"except Exception as e:\n",
|
220 |
+
" print(f\"Error loading CSV file: {e}\")\n"
|
221 |
+
]
|
222 |
+
},
|
223 |
+
{
|
224 |
+
"cell_type": "code",
|
225 |
+
"execution_count": null,
|
226 |
+
"id": "2543edf6",
|
227 |
+
"metadata": {},
|
228 |
+
"outputs": [],
|
229 |
+
"source": []
|
230 |
+
}
|
231 |
+
],
|
232 |
+
"metadata": {
|
233 |
+
"kernelspec": {
|
234 |
+
"display_name": "Python 3 (ipykernel)",
|
235 |
+
"language": "python",
|
236 |
+
"name": "python3"
|
237 |
+
},
|
238 |
+
"language_info": {
|
239 |
+
"codemirror_mode": {
|
240 |
+
"name": "ipython",
|
241 |
+
"version": 3
|
242 |
+
},
|
243 |
+
"file_extension": ".py",
|
244 |
+
"mimetype": "text/x-python",
|
245 |
+
"name": "python",
|
246 |
+
"nbconvert_exporter": "python",
|
247 |
+
"pygments_lexer": "ipython3",
|
248 |
+
"version": "3.11.5"
|
249 |
+
}
|
250 |
+
},
|
251 |
+
"nbformat": 4,
|
252 |
+
"nbformat_minor": 5
|
253 |
+
}
|