PYTHON SQL
PYTHON SQL
print(ved_med)
print(ved_med.loc[:,['medicinename','price']].to_string(header=False,index=False))
print(ved_med.tail(4))
print(ved_med[ved_med.price>20])
plt.bar(ved_med['medicinename'],ved_med['price'],color=['r','g','b','c','y'])
plt.title("Medicine Report",color='blue')
plt.xlabel("Medicine Names",color='red')
plt.ylabel("Price",color='magenta')
plt.legend(['Price'])
plt.grid(True)
plt.savefig("output1.png")
plt.show()
#solution2
import pandas as pd
d={'Ename':['Anil','Akshay','Ajay','Varun','Siddharth','Rajesh'],'Post':['Manager','Clerk',
'Manager','Analyst','Developer','Clerk'],
'Salary':[65000,33000,75000,66000,60000,35000],'Dt_join':['2018-03-02','2018-05-
01','2018-09-15','2018-04-11','2018-10-12','2018-06-12']}
df=pd.DataFrame(d,index=[101,102,103,104,105,106])
print(df)
em=df.loc[:,['Ename','Post','Salary']]
print(em[em.Salary>60000].to_string(header=False,index=False))
df.loc[df.index[-1]+1]=['Ranveer','Analyst',65000,'2020-01-06']
print(df.iloc[-1])
df.to_csv('employees.csv')
plt.plot(df['Ename'],df['Salary'],color='r')
plt.title("Employee Analysis",color='blue')
plt.xlabel("Employee Names",color='red')
plt.ylabel("Salary",color='magenta')
plt.legend(['Salary'])
plt.grid(True)
plt.savefig("EMP.png")
plt.show()
#solution3
import pandas as pd
import matplotlib.pyplot as plt
d={'country':['China','India','US','Indonasia','Brazil','Pakistan'],'population':[13797500
00,1330780000,324882000,260581000,206918000,194754000],'birthrate':[12.00,21.
76,13.21,18.84,18.43,27.62],'updatedate':['2010-10-01','2010-01-04','2009-03-
01','2009-04-01','2008-08-05','2010-04-05'] }
country=pd.DataFrame(d)
print(country)
print(country[country['country']=='China'].to_string(header=False,index=False))
print(country[country['country']=='India'].to_string(header=False,index=False))
c=country.loc[:,['country','population','birthrate']]
print(c[c['country']=='Brazil'].to_string(header=False,index=False))
print(c[c['country']=='Pakistan'].to_string(header=False,index=False))
plt.bar(country['country'],country['population'],color=['r','g','b','c','m','y','k'])
plt.title("Population Report")
plt.xlabel("Country")
plt.ylabel("Population")
plt.grid()
plt.show()
country.to_csv('country.csv')
SQL QUERIES
1. Write the SQL query commands based on the following table Charity:
Item_id Itemname Price Qty Pdate
1 Shoes 7500 5 2022/11/30
2 Socks 475 3 2022/08/25
3 Jeans 3500 5 2022/10/19
4 T-Shirts 1400 4 2022/11/30
2. Write the SQL query commands based on the following table Employee:
NO NAME DEPARTMENT DOJ SALARY SEX
(i) To display Wno, Name, Gender from the table WORKER in descending order of Wno.
(ii) To display the Name of all the FEMALE workers from the table WORKER.
(iii) To display the WNo and Name of those workers from the table WORKERwho are born
between ‘1987-01-01’ and ‘1991-12-01’.
(iv) To count and display MALE workers who have joined after ‘1986-01-01’.
(v) To display name, department and city of worker whose WNO is less than 1003.