NEP -PYTHON

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8

PART B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

8. Create data frame from excel sheet and perform simple operations

 
 import pandas as pd

# Read data from Excel into a DataFrame
file_path = "data.xlsx"
df = pd.read_excel(file_path)

# Print the DataFrame
print("Original DataFrame:")
print(df)

# Perform simple operations on the DataFrame

# Add a new column 'Bonus' which is 10% of the 'Salary'
df['Bonus'] = df['Salary'] * 0.1

# Print the DataFrame after adding the 'Bonus' column
print("\nDataFrame after adding the 'Bonus' column:")
print(df)

# Calculate the average age
average_age = df['Age'].mean()
print("\nAverage Age:", average_age)

# Find the person with the highest salary
highest_salary_person = df.loc[df['Salary'].idxmax(), 'Name']
print("\nPerson with the highest salary:", highest_salary_person)

# Filter the DataFrame to include only people with a salary greater than 35000
filtered_df = df[df['Salary'] > 35000]
print("\nFiltered DataFrame:")
print(filtered_df)