Advertisements
Advertisements
Question
Consider the DataFrame df shown below.
| Name | Department | Salary | |
| 0 | Rohan Sharma | IT | 75000 |
| 1 | Meera Kapoor | HR | 68000 |
| 2 | Aarav Singh | Finance | 85000 |
| 3 | Nisha Singh | Marketing | 72000 |
| 4 | Aditya Verma | IT | 80000 |
Write Python statements for the following tasks:
- Print the last three rows of the DataFrame
df. - Add a new column named
"Experience"with values [5, 8, 10, 6, 7]. - Delete the column
"Salary"from the DataFrame. - Rename the column "Department" to
"Dept". - Display only the
"Name"and"Salary"columns from the DataFrame
Code Writing
Advertisements
Solution
-
print(df.tail(3)) -
df['Experience'] = [5, 8, 10, 6, 7] -
df.drop(columns=['Salary'], inplace=True) -
df.rename(columns={'Department': 'Dept'}, inplace=True) -
print(df[["Name", "Salary"]])
shaalaa.com
Is there an error in this question or solution?
