(i) Print the last three rows of the DataFrame:
To view the last three rows, use the
tail() function.
print(Doctor.tail(3))
Explanation: The
tail() method displays the last n rows. Here, n is 3.
(ii) Display the names of all doctors:
To display only the 'Name' column, use:
print(Doctor['Name'])
Explanation: This selects only the 'Name' column and prints it.
(iii) Add a new column 'Discount':
To add a new column with the same value for all rows, use:
Doctor['Discount'] = 200
Explanation: This creates a new column named 'Discount' and assigns 200 to every row.
(iv) Display rows with index 2 and 3:
To select specific rows by index, use the
loc indexer with a list of index labels.
print(Doctor.loc[[2, 3]])
Explanation: The
loc method is label-based indexing for rows.
(v) Delete the column 'Department':
To drop a column from a DataFrame, use
drop with
axis=1.
Doctor = Doctor.drop('Department', axis=1)
Explanation: The
drop() function removes the specified column and updates the DataFrame.