|
42 | 42 | "np.random.seed(0)\n",
|
43 | 43 | "num_records = 100\n",
|
44 | 44 | "\n",
|
45 |
| - "AIRLINES = ['PIA', 'Qatar Airways', 'Emirates',\"Japan Airways\",\"American Airline\",\"Tata Airline\", \"Saudi Airline\"]\n", |
| 45 | + "AIRLINES = [\n", |
| 46 | + " \"PIA\",\n", |
| 47 | + " \"Qatar Airways\",\n", |
| 48 | + " \"Emirates\",\n", |
| 49 | + " \"Japan Airways\",\n", |
| 50 | + " \"American Airline\",\n", |
| 51 | + " \"Tata Airline\",\n", |
| 52 | + " \"Saudi Airline\",\n", |
| 53 | + "]\n", |
46 | 54 | "\n",
|
47 | 55 | "CITIES = [\n",
|
48 | 56 | " \"Dubai\",\n",
|
|
64 | 72 | "]\n",
|
65 | 73 | "\n",
|
66 | 74 | "flights_data = {\n",
|
67 |
| - " 'FlightID': np.arange(1, num_records + 1),\n", |
68 |
| - " 'Airline': np.random.choice(AIRLINES, num_records),\n", |
69 |
| - " 'Destination': np.random.choice(CITIES, num_records),\n", |
70 |
| - " 'Duration': np.random.randint(60, 360, num_records), # Duration in minutes\n", |
71 |
| - " 'Delay': np.random.randint(0, 120, num_records) # Delay in minutes\n", |
| 75 | + " \"FlightID\": np.arange(1, num_records + 1),\n", |
| 76 | + " \"Airline\": np.random.choice(AIRLINES, num_records),\n", |
| 77 | + " \"Destination\": np.random.choice(CITIES, num_records),\n", |
| 78 | + " \"Duration\": np.random.randint(60, 360, num_records), # Duration in minutes\n", |
| 79 | + " \"Delay\": np.random.randint(0, 120, num_records), # Delay in minutes\n", |
72 | 80 | "}\n",
|
73 | 81 | "\n",
|
74 | 82 | "flights_df = pd.DataFrame(flights_data)\n",
|
75 |
| - "flights_df.to_csv('random_flights_data.csv', index=False)\n", |
| 83 | + "flights_df.to_csv(\"random_flights_data.csv\", index=False)\n", |
76 | 84 | "\n",
|
77 | 85 | "# Read the CSV file using pandas\n",
|
78 |
| - "flights_df = pd.read_csv('random_flights_data.csv')\n", |
| 86 | + "flights_df = pd.read_csv(\"random_flights_data.csv\")\n", |
79 | 87 | "\n",
|
80 | 88 | "# Display the first few rows of the dataframe\n",
|
81 | 89 | "print(flights_df.head())\n",
|
82 | 90 | "\n",
|
83 | 91 | "# Perform operations on the data\n",
|
84 | 92 | "# Example: Calculate the average duration and delay for each airline\n",
|
85 |
| - "average_stats = flights_df.groupby('Airline')[['Duration', 'Delay']].mean()\n", |
| 93 | + "average_stats = flights_df.groupby(\"Airline\")[[\"Duration\", \"Delay\"]].mean()\n", |
86 | 94 | "print(average_stats)"
|
87 | 95 | ]
|
88 | 96 | }
|
|
0 commit comments