Insert, Delete and Update Command in Pandas

Get Job-Ready: Data Analysis using Python with 70+ Projects Start Now!!

Program 1

Pandas Dataset

import pandas as pd
emp=pd.read_excel("D://mypandas/employee.xlsx")
print(emp)

# Delete
# emp=emp.drop(emp[emp.gender=='male'].index)
# # emp=emp.drop(emp[emp.totalsalary==10000].index)
# print(emp)

# Update

# #emp.loc[emp['totalsalary']==7000]=7600
# emp.loc[emp['totalsalary']==15000,'totalsalary']=25000
# print("--------------------------------------------------------")
# print(emp)

# Largest
#print(emp.nlargest(5,columns='totalsalary').tail(5))
#print(emp.nlargest(10,columns='HRA'))
#print(emp.columns)
#print(emp)

# Append(Insert)
#emp=emp._append({'id':36,'empname':'Rajeev Gupta','empdept':'CSE','gender':'M','HRA':8000,'TA':7000,'DA':5000,'totalsalary':20000},ignore_index=True)
# eid=int(input('Enter Employee Id: '))
# ename=input('Enter Employee Name: ')
# edept=input('Enter Employee Department: ')
# egender=input('Enter Employee Gender: ')
# ehra=int(input('Enter Employee HRA: '))
# eta=int(input('Enter Employee TA: '))
# eda=int(input('Enter Employee DA: '))
# etotal=ehra+eta+eda
# emp=emp._append({'id':eid,'empname':ename,'empdept':edept,'gender':egender,'HRA':ehra,'TA':eta,'DA':eda,'totalsalary':etotal},ignore_index=True)
# print("----------------------------------------------------------------------")
# print(emp)
# print("Record Inserted ")
# emp.to_excel("D://mypandas/employee12345.xlsx")
# print("New File Created")

 

Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

courses
Image

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *