File size: 7,006 Bytes
3d3c84d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "985f02de",
   "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>Employee Name</th>\n",
       "      <th>Age</th>\n",
       "      <th>Department</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>John</td>\n",
       "      <td>31</td>\n",
       "      <td>HR</td>\n",
       "      <td>108189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Alice</td>\n",
       "      <td>39</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>100371</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Bob</td>\n",
       "      <td>52</td>\n",
       "      <td>Marketing</td>\n",
       "      <td>90333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Carol</td>\n",
       "      <td>29</td>\n",
       "      <td>Sales</td>\n",
       "      <td>69356</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>David</td>\n",
       "      <td>25</td>\n",
       "      <td>Finance</td>\n",
       "      <td>79835</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Employee Name  Age   Department  Salary\n",
       "0          John   31           HR  108189\n",
       "1         Alice   39  Engineering  100371\n",
       "2           Bob   52    Marketing   90333\n",
       "3         Carol   29        Sales   69356\n",
       "4         David   25      Finance   79835"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import random\n",
    "import numpy as np\n",
    "\n",
    "# Create random data\n",
    "data = {\n",
    "    'Employee Name': ['John', 'Alice', 'Bob', 'Carol', 'David'],\n",
    "    'Age': [random.randint(22, 55) for _ in range(5)],\n",
    "    'Department': ['HR', 'Engineering', 'Marketing', 'Sales', 'Finance'],\n",
    "    'Salary': [random.randint(50000, 120000) for _ in range(5)]\n",
    "}\n",
    "\n",
    "# Convert to DataFrame\n",
    "df = pd.DataFrame(data)\n",
    "\n",
    "# Save to Excel\n",
    "df.to_excel('employee_data.xlsx', index=False)\n",
    "\n",
    "# Save to CSV\n",
    "df.to_csv('employee_data.csv', index=False)\n",
    "\n",
    "# Display the created DataFrame\n",
    "df\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e6b3ffce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Excel Data:\n",
      "  Employee Name  Age   Department  Salary\n",
      "0          John   45           HR   68212\n",
      "1         Alice   26  Engineering   84012\n",
      "2           Bob   39    Marketing  111842\n",
      "3         Carol   31        Sales   96286\n",
      "4         David   52      Finance  115640\n"
     ]
    }
   ],
   "source": [
    "# Reading the Excel file\n",
    "df_excel = pd.read_excel('employee_data.xlsx')\n",
    "\n",
    "# Display the DataFrame\n",
    "print(\"Excel Data:\")\n",
    "print(df_excel)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5c83abd8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CSV Data:\n",
      "  Employee Name  Age   Department  Salary\n",
      "0          John   45           HR   68212\n",
      "1         Alice   26  Engineering   84012\n",
      "2           Bob   39    Marketing  111842\n",
      "3         Carol   31        Sales   96286\n",
      "4         David   52      Finance  115640\n"
     ]
    }
   ],
   "source": [
    "# Reading the CSV file\n",
    "df_csv = pd.read_csv('employee_data.csv')\n",
    "\n",
    "# Display the DataFrame\n",
    "print(\"CSV Data:\")\n",
    "print(df_csv)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "fe7dc33a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Excel Data Loaded Successfully\n",
      "  Employee Name  Age   Department  Salary\n",
      "0          John   45           HR   68212\n",
      "1         Alice   26  Engineering   84012\n",
      "2           Bob   39    Marketing  111842\n",
      "3         Carol   31        Sales   96286\n",
      "4         David   52      Finance  115640\n",
      "CSV Data Loaded Successfully\n",
      "  Employee Name  Age   Department  Salary\n",
      "0          John   45           HR   68212\n",
      "1         Alice   26  Engineering   84012\n",
      "2           Bob   39    Marketing  111842\n",
      "3         Carol   31        Sales   96286\n",
      "4         David   52      Finance  115640\n"
     ]
    }
   ],
   "source": [
    "# Try reading the Excel file\n",
    "try:\n",
    "    df_excel = pd.read_excel('employee_data.xlsx')\n",
    "    print(\"Excel Data Loaded Successfully\")\n",
    "    print(df_excel)\n",
    "except FileNotFoundError:\n",
    "    print(\"Error: Excel file not found!\")\n",
    "except Exception as e:\n",
    "    print(f\"Error loading Excel file: {e}\")\n",
    "\n",
    "# Try reading the CSV file\n",
    "try:\n",
    "    df_csv = pd.read_csv('employee_data.csv')\n",
    "    print(\"CSV Data Loaded Successfully\")\n",
    "    print(df_csv)\n",
    "except FileNotFoundError:\n",
    "    print(\"Error: CSV file not found!\")\n",
    "except Exception as e:\n",
    "    print(f\"Error loading CSV file: {e}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2543edf6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}