Site icon DataFlair

How to Use SQL 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.nlargest(5,columns='totalsalary'))
#print(emp.nlargest(5,columns='totalsalary').tail(4))
#Insert

# Update
# emp.loc[emp['totalsalary']==10000]=15000
# emp.loc[emp['totalsalary']==15000,'totalsalary']=25000
# print(emp)

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









#print(emp.head(6))
#print(emp.tail(6))
#select * from employee where salary>10000;
#print(emp.columns)

#select * from employee where salary>10000 and edept='CS';
#print(emp[(emp.totalsalary>10000) & (emp.empdept>'CS')][['empname','totalsalary','empdept']])

#select * from employee where salary in(60000,70000,80000);
#print(emp[~emp.totalsalary.isin([7000,8000,12000])][['empname','totalsalary','empdept']])
#print(emp[(emp.empdept=='CS')|(emp.empdept=='IT')][['empname','totalsalary','empdept']])

 

Exit mobile version