0% found this document useful (0 votes)
20 views

Practical file 12th

Practical file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
20 views

Practical file 12th

Practical file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 19
PYTHON PROGRAMS Questions Createa series of these numbers:33,55,65,29,19,23. reatea series of 10 numbers starting with 41 and with the increment of 3. Create a series of 10 numbers using ndarray. Create a series and print the top 3 and bottom 3 elements using the head and tail functions. Write code to show al attributes of series. Use seriesin QI. Use Series created in Q2 ad find output of following commands:- sf:2), s[1:3] & s[[1,3,4]]. Write code to change value 29 and 23 from series Q1. Write code to sort series in descending order-(Use Q3). Create a dataframe countries using a dictionary which stored 5 country name, capitals and populations of the country. Index will be years. Write a program to show alll attributes of dataframe created in Q9. Create a dataframe players to store 10 players with their highest and lowest score no_of matches columns. Player names are indices of dataframe. Perform following questions:- 1a) Show data of any two players using loc function. 1b) Show any two columns. c) Show data of two rows and two colurans using loc function. d)Make use of rename command to change column name no_of matches to Matches played. e) Drop rowof last player. ‘Make multiple bar graph for dataframe created in Q11. Create line graph for temp. seven days of week. Create histogram to show salesof one month data. Createcsv file from dataframe players. Make sure null values are handled properly. Create csv file in excel. Open csv in dataframe, Make use of nrows ‘command. Create database DATA Create the following table product Table: Products Apple Sony Philips iPhone LED TV Bluetooth Speaker Show table structure, ‘Show records of table products. Show products of pcode P1001 and P1005, ‘Show data of products starting with i ‘Show data ofall products whose quantity>50 and price>30000. |Show sum of price ofall products. Show product names in upper case and also length of all products. ‘Show product name and qty joined with space under heading “Product and Qty”. Fra Display first2 and last2 letters from Pname. Write queries using emp! table: ‘Show totalemployeesworking ineach department. ‘Show avg salary of each job ‘Show min salary of each department where minimum employees are > 3. Write queries using empl and dept table: ‘Show employee names and location of job. ‘Show avg salary of employees working in sales department. ‘Show ename, salary,dname, and location and all employees. ED” ‘current date and time. Display day of week, day ofyear and day name for current date. a drop the table product 5 PYTHON PROGRAM 1) Create a series of these numbers: 33,55,65,29,19,23. cope: import pandas as pd 1d Series({33,55,65,29,19,23]) print(s1) ‘ouTPu’ Cleo ir) 2) Create aseries of 10 numbers starting with 41 and with the increment of. cope: import pandasas pd sn= 41 im=3 af] for iin range(10}: a.append(sn) sn= sneim 1d Series(a) print(m) ouTpuT:- oye UL 3) Createa series of 10 numbers using ndarray. CODE: import pandas as pd import numpy as np \d.Series(np.arange(1, 11) print(s) OUTPUT:- dtype: inté4 4) Create a series and print the top 3 and bottom 3 elements using the head and tail functions, CODE: import pandas as pd 10, 20, 30, 40, 50, 60, 70, 80, 90, 100] d.Series(s) print(s1.head(3)) print(s1.tail(3)) ouTPUT- 5) Write CODE to show all attributes of series. Use series created in Q1. CODE import pandas as pd 5=pd.Series([33,55,65,29,19,23]) print(s5{:]) ouTpur:- Cie 6) Use Series created in Q2 and find OUTPUT of following commands: s{: :2] s[1:3] s{{1,3,4]] CODE: print{m{::2]) print(m{2:3)) print(m({2,3,4]]) OUTPUT:- 8 Cie Uns rel ar) Clover ns cer) ce Cisvoceme Uns Write CODE to change value 29 and 23 from series of Q1. cope: import pandas as pd si=pd.Serles([33,55,65,29,19,23}) s1[3]=30 s1(5]=28 print(s1) ourpur:- Chey eee Cet) Write CODE to sort series in descending cope: import pandas as pd Import numpy as np s=pd.Serles(np.arange(1, 11)) print(s) s=s.sort_values(ascending=False) print(s) ourpur: as order-(Use — Q3). 9) Create a dataframe countries using a dictionary which stored 5 countryname, capitals and populations of the country. Index will be years, cove import pandas as pd countrles= pd.DataFrame(({ ‘Country’: ['USA’, ‘Canada’, 'UK’, ‘Germany, 'France'], ‘capital’: [Washington D.C. 'Ottawa', ‘London’, ‘Berlin’, "Paris'], ‘Population’: (331002651, 37742154, 67886011, 83783942, 65273511] 3), ['2021 1021','2022', '2023','2024']) print{cou ntries) OUTPUT- fers) Capital Population ry Ut cee BER. feTT Tr Chae) Brae vaLs UK OE aa Sg ed 10) Write program to show all attributes of dataframe created in Q9. cope: import pandas as pd import numpy as np ‘Country’: ['United States’, France’, ‘Brazil, Japan’, ‘Australia'], ‘Capital’: ['Washington, D.C. ‘Paris’, ‘Brasilia’, ‘Tokyo’, 'Canberra'], ‘Population’: (1000000, 2000000, 1500000, 2500000, 1800000]} $10 = pd.DataFrame(data, index=[2020, 2021, 2022, 2023, 2024]) print(S10[:]) ouTPUT- Cars: United state Peery 11) Create dataframe players to store 10 players with their highest and lowest score no_of matches columns. Player names are indices of dataframe. perform following questions:- a) Show data of any two players using loc function. b) Show any two columns. )Show data of two rows and two columns using loc function. d) Make use of rename command to change column name no_of_matches to Matches_played €) drop row of last player. cope: import pandas as pd players=pd.DataFrame( { ‘layer’: ['Playert!, 'Player2', 'Player3', 'Player4!, 'Players', 'Player6', 'Player7’, ‘Players’, ‘Players, 'Player10', 'Highest_Score’: (98, 89, 95, 87, 99, 92, 96, 90, 88, 94], ‘Lowest_Score’: [45, 55,50, 42, 48, 51,46, 56, 49, 47], 'Matches_played': (30, 35, 32, 33,31, 29, 34, 30, 36, 37] y players.set_index('Player’, inplace=True) print(‘a)Show data of any two players usingloc function’) print(players.loc{{'Player1’, 'Player3"]}) print('b}Show any two columns’) print(players{{'Highest_Score’, 'Lowest_Score'}}) print('c) Show data of two rows and two columns using loc function’) print(players.loc{{'Player2', Players'], [‘Highest_Score’, 'Lowest_Score']]) print('d) Make use of rename command to change column name no_of_matches to Matches_played') players.rename(columns={'Matches_played’: ‘no_of_matches'}, inplace=True) print('Drop the row of the last player’) players.drop('Player10’, inplace=True) print('Displaythe updated DataFrame') print(players) OUTPUT:- 12) Make multiple bar graph for dataframe created in Q.11 CODE: Import pandas as pd import matplotlib.pyplot as pit players = pd.DataFrame({ ‘Player’: ‘Player’, 'Player2’, 'Players', Player4’, ‘Players’, ‘Players’, 'Player7’,'Player8', ‘Player9', 'Player10'], "Highest_Score': [98, 89, 95, 87,99, 92, 96, 90,88, 94], "Lowest_Score':[45,55, 50, 42, 48, 51,46, 56, 49, 47], 'Matches_played': [30, 35, 32, 33, 31, 29, 34, 30, 36, 37] » players.set_index('Player', inplace=True) players{['Highest_Score’, '‘Lowest_Score']].plot(kind="bar, figsize=(10, 6)) pit.title('Highest and Lowest Score for Players’) pltxlabel('Players') pltyylabel('Scores') plt.xticks(rotation=45) plt.show() OUTPUT:- OM hk he Oe CE 13) Create line graph for temp. of seven days of week CODE: Import matplotlib.pyplot as plt days_of_week = ['Monday,, ‘Tuesday’, ‘Wednesday’, ‘Thursday, ‘Friday’, ‘Saturday’, ‘sunday'] temperature = [65, 68, 70, 72, 59, 57, 73] pit.plot(days_of_week, temperature, marker='o', inestyl pit-title("Temperature for Seven Days of the Week’) pit.xlabel('Day of the Week’) pit.ylabel('Temperature (°F)') pit.show() ourpuT:- ‘Temperature for Seven Days of the Week ‘Monday Tuesday Wednesday Thursday friday Saturday Sunday Day of the Week 14) Create histogram to show sales of one month data. cope: import matplotlib.pyplot as pit sales_data = (110, 125, 125, 145, 135, 115, 110, 120, 135, 140, 130, 130, 140, 175, 135, 145, 125, 135, 140, 150, 140, 130, 160, 155, 125, 160, 140, 145] pit hist(sales_data, bins=15, edgecolor="y') plt.title('Sales Histogram for One Month’) pit.xlabel('Sales Amount’) pit.ylabel('Frequency') pit.show() OuTPUT:- Sales Histogram for One Month uo 080 Sales Amount 15) Create csv file from dataframe players, Make sure null valuesare handled properly. cope: players=pd.DataFrame( { ‘Player’: [’Playert', 'Player2’, 'Player3', ‘Player4’, 'PlayerS', ‘Players’, 'Player7’, 'Player8','Player9', 'Player10'), 'Highest_Score': [100, 150, 80, None, 200, 90, 110, 130, None, 170}, "Lowest _Score': [30, 40,20, 50, 60, 35, 25, None, 55, 70], 'Matches_played': [50, None, 60, 55, 40, 48, None, 42, 47, 49] a) players.set_index('Player', inplace=True) players=players.fillna(‘N/A’) players.to_csv(‘players_data.csv’) ourPuT:- ayer Mighest Score Lowest Score Ne of Mathes 40WA « 0 2 16) Create csv file in excel. Open csv in dataframe. Make use of nrows ‘command, CODE: Import pandas as pd Df=pd.read_csv(‘csv.csv’,nrows=5) print(0f) UTPUT:- Population Hospitals Schools Govt_officers Multiplex Malls 123415121 132-3871 54152 15247 45364 165345345 195 4025 «315427 2444287645 214763548 1001258 2457515284 51470 514582475 «145.1240 43200 © 433351433 Create the following table products. i eee AM Stoo P1001 | iPad 120| 15000] Apple P1002| LEDTV__| 100| 85000| Sony DSLR P1003 | Camera 10 | 25000] Philips P1004| iPhone__| 50 | 95000] Apple P1005 LEDTV__| 20 | 45000] MI. Bluetooth Speaker P1006 100] 20000] Ahuja 16 Show table structure. 1) Ose i Ee Cees U Me ae DSc eae ose aT rely urs e3] Lae varchar(20) ree | Crete I pt | Dae | | | i] is] | Price | int rae Company | varchar(10) na ws in set (0.06 si 2) Show records oftable products. eee ees R rr are Pcode | Pname eT) PEO) 25000 rT) 3) Ee mer ett ae me TM rr tes -> where Pcode in ('P1001', 'P1005'); " | Company | iPad | 120 | 15000 LED Tv | 20 | 45000 + 7 Cel eee ee eer ad Se eae Se Cua os + 5060 | Apple | Cee yacd NEE eet eae et mee ta Sse) se OME Bs select sum(Price)"Total_Price" from Products; = " | Total_Price | 18 '8) Show product name and qty joined with space under heading “product and Qty’ er Enemy PM Sse or ers resets i i ote f eRe | | DSLR Camera | eo | etc eves) | te I rons in set (0.60 19 10) Write queries usingemp! table: in set (0.00 sec) cl ory tr ea Er mets Show min salary of each department where minimum employees are>3. mysql> select deptno , min(sal) from enpl Seren mC CMe eur meu Cuet Een rows in set (0.60 sec 20 11) Write queries ising empl and dept table Show employee names and their location of job Sec ee eee cee er et SCS ments on oma eee Cae mer Cee CS CET or et SETH on Ce ar BINA en re ee, select avg(sal) from empl e, dept PO eRe Lr er ac | " | 5 ce careers Peers ara 7 SALES SETH air ase | Reig orn | KOLKATA marys | KOLKATA onc se: ers | NEW DELK ocr eis ery mera. a SHIVANSH | 2U50 Raa ees ANIR Emme isc rg fin eee Brrr erm ae ie Eee aa Pea) cant Semel is Crd 2 12) Display current date and time. mysql> SELECT NOW()"Current_Date_Time"; ce | Current_Date_Time a Hy chad fh 22

You might also like