The code to create the DataFrame and perform the requested operations is as follows:
import pandas as pd
# Dictionary for creating DataFrame
data = {'EName': ['Kush', 'Ruchika', 'Divya', 'John'],
'Salary': [10000, 12000, 20000, 25000]}
# Create DataFrame from dictionary
empdf = pd.DataFrame(data)
# Print DataFrame
print(empdf)
# Display EName and Salary with Salary more than 20000
high_salary_df = empdf[empdf['Salary'] > 20000]
print(high_salary_df[['EName', 'Salary']])
# Add a column 'Commission' with values as 5% of the Salary
empdf['Commission'] = empdf['Salary'] * 0.05
print(empdf)
This code will create the empdf
DataFrame, display the EName
and Salary
for those with salaries greater than 20000, and add a new column named 'Commission' with values calculated as 5% of the Salary.