Il 0% ha trovato utile questo documento (0 voti)
3 visualizzazioni23 pagine

Ip Pallavi ....

Gb

Caricato da

purnimajaint1
Copyright
© © All Rights Reserved
Per noi i diritti sui contenuti sono una cosa seria. Se sospetti che questo contenuto sia tuo, rivendicalo qui.
Formati disponibili
Scarica in formato PDF o leggi online su Scribd
Il 0% ha trovato utile questo documento (0 voti)
3 visualizzazioni23 pagine

Ip Pallavi ....

Gb

Caricato da

purnimajaint1
Copyright
© © All Rights Reserved
Per noi i diritti sui contenuti sono una cosa seria. Se sospetti che questo contenuto sia tuo, rivendicalo qui.
Formati disponibili
Scarica in formato PDF o leggi online su Scribd
Sei sulla pagina 1/ 23
AIM: ‘To write a Python program to create a Series object that stores the Employee names as index and their Salary as values SQURCE CODE; Import pandas as pd Amport Bumpy as np Section=["A','B', 'C') ‘Contribution=np. array ((6700,5500,np.NaN]) Sepd. Series (datasContribution, index=section) print (8) ‘Do you want to update the salary of the employecty/a}?:y ‘Enter the name of the employes: Am ‘Enter the mew salary: 58000, ‘Salary updated successfully! CREATING A PYTHON PROGRAM FOR MODIFYING OR UPDATING EXISTING VALUES OF SERIES OBJECT, AIM: To Write a Python program to create a Series object with Employee names as the index and their salaries as values. Accept the name of the employee whose salary needs to be changed, along with the new salary, and update it in the Series, Mamet input("Enter the name of the employee: ") Mame is 8: new salary = float{input{ Enter the new salary) [Mame] = new salary print(\aSalary updated successfully!) i eines Renee arson cetset Print{"\nEmployee not found in the records.") “ print{"\ Thane You!!!") SAMPLE OUTPUT: The Addition of two series cbject 4: a 12.0 b 25.0 ° Nan dtype: fleatea The Subtraction of two series object is: a 8.0 b 18.0 © Nan dtype: floatea ‘The Multiplication of two series object is: a 20.0 b 100.0 . Nan dtype: floatéa ‘The Division of two series object is: a 5.0 > 0 c NaN dtype: floatéé PERFORMING MATHEMATICAL OPERATIONS ON SERIES OBIECTS AIM: To create a program in python to perform following mathematical Operations on Two Series objects: (i) Addition (ii) Subtraction (iii) Multiplication (iv) Division. pindexs{ a’, =pd. Series ({2,5],index=['a','b’)) Fint ("The Addition of two series object is:") int (61+82) int ("The Subtraction of two series object is:") -int (81-82) int ("The Multiplication of two series object i int (81*82) int ("The Division of two series object is:") int (81/82) ING A PYTHON PR¢ M FOR, EQUR ZONES USING SERIES. To write a Python program to create two series i.e. population and average income of Four Zones, and then calculate per capita income storing in third pandas series print it. Source Code; are | population=pd.Series([5200,2100,4523,3422}, inden=[ East’, West’, South’, Noxth’]) | avgincome=pd.Series([117832,587324,171802,235038},index=[ East’, West, South’, North] | perCapitalncome=avgincome/population print{'Pereapita Income of Four Zones are:") print("\n") Print{perCapitalncome) SAMPLE OUTPUT: The index of the Series is: Index([' The data type of the Series is: ints4 The size of the Series is: 5 is: (5,) False te'], dtype='object') CREATING A PYTHON PROGRAM TO DISPLAY ATTRIBUTES OF A SERIES, AIM: To write a Python program to create a Series using list and display the following attributes of the Series: (i) index (ii) dtype (iti) size (iv) shape (v) hasnans import pandas as pd ‘L=(10, 45,67,3,43] S=pd. Series (L,index=[ s'B','e", 'a",'8°1) Iprint ("The index of the Series is:",8, index) lpeint ("The data type of the Series is:",8.dtype)| Ipeint("The size of the Series is:",S.size) [print shape of the Series is:",S. shape) [print ("The NaN of the Series is:",S-hasnans) SAMPLE OUTPUT: Name Stul = Arun Stu2 Bala Stu3 Charan age 21 23 22 NESTED LIST. ALM: To write a Python program to create a panda’s Data Frame for the following table Using Nested list: Name [Age | ‘stu [Arun 2 stu2 [sale 23 stus_|charan 22 SOURCE CODE: int (D) [import pandas as pd Le((*Arun',21),{'Bala’,23],{"Charan',221] (D=pd.DataFrame(L,index=['stul','stu2','Stu3"), column: "Name! , ‘Age! 1) SAMPLE OUTPUT: The details of Toys are: AP 7916 op (8508 MP 7226 uv. 1617 Name: Toys, dtype: int64 ‘The details of AP and OD are: Toys Books Uniform shoes 7916 61896 610 610 8508 8208 508 6798 ‘The details of MP and U.P are: Books Uniform 6149 ou. 6157 457 Consecutive 3 Rows and 3 Columns are: Toys Books Uniform AP 7916 61896 610 op 850% 08 508 M.P 7226 6149 611 (CREATING A PYTHON PROGRAM FOR ACCESSING VALUES OF ROWS AND. COLUMNS OF A DATAFRAME, aM: To write a Python program to create a panda’s DataFrame called DF for the following table Using Dictionary of List and perform the following operations: toe | ate [ent | roe | soe [oe | ae thes @ To Display only column "Toys! from DataFrame DF. (8) To Display the row details of ‘AP’ and ‘OD’ from DataFrame DF (i) To Display the column "Books" and ‘Uniform’ for 'M.P" and ‘U.P" from DataFrame DF, (@) To Display consecutive 3 rows and 3 columns from DataFrame DF. SOURCE CODE: lagant panies oa pd [bet "toys (7926, 8608,7226,76171, ‘Boake s (61096, 6268 6245, 61892, Ontoew’ + (620,508, 612,457 , ‘Shoss'# (8810, 6788, 9615,64572) [beepa.atarrame(0,ndex=(‘A2°,/c0!, 4.8), °UPT SAMPLE OUTPUT: After Adding a new column Toys Books Uniform Shoes AP 7916 61896 610 8810 op 8508 «8208 508 6798 M.P 7226 «6149 611 9611 U.P 7617 6157 457 6457 After Deleting M.P details: Toys Books Uniform Shoes AP 67916 61896 610 10 op 8508 8208 508 6798 U.P 7617 6157 457 6457 Bags 5891 8628 9785 4475 Bags 5891 8628 4475 AM: ‘To write a Python program to create a panda’s DataFrame called DF for the following table Using Dictionary of List and perform the following operations: a ras | a [ror (0 Insert a new column “Bags” with values as [5891, 8628, 9785, $475]. (i Delete the row details of M.P from DataFrame DF. 17916, 8508,7226, 7617), [61896,8208, 6149, 61571, ‘uniform’ (610,508, 611,457), "shoes: (8810, 6798, 9611,6457] ) [DP=p4.DataPrame (D,index={ AP! , 00", M.2',°V.2'}) [DF pags’ ]={5891, 8628, 9785, 4475] # Adding « new column Bags ‘Sample Output: Original Detrrame ‘AP. Assam Sikkin TH AIMS. Fo 30 mat Lo 34 Mat Fees 28000 3300.0 27000923000 '15000.0 ‘Changing the name tom AP te Anam: ‘Andhra Assam Sikkiea TH AIMS. Fo 0 man ‘to 34 mam Fees 25000 93000.0 27000.0. 23000 150000 ‘Cousting and aisphaying noe-aN vatues of each colama: perreary Increasing the fees of al coteges by 6% “Ananra Assam ‘Sikkim TN AIMS ac ““i70 “60” MN 22.0" 7, Po 300 Maw 20 34.0 Haw TS 7180.0 7260 1000 46.0. 6730 Pees 26280.0 34650.0 28950.0 241500 18750.0 ‘Replacing all Nad values with O: ‘Aedhen Assam Siutin TN ANMS. PC 30.9 00 19 280 00 TS 7180.0 7260 1000. 46.0 6730 Pees 26280.0 94660.0 20950.0 2410.0 18750. (CREATING A PYTHON PROGRAM TO PERFORM OPERATIONS ON A DATAFRAME (RENAME. COUNT. UPDATE. REPLACE) AIM: ‘To write a Python program to create a pandas DataFrame to analyze number of Government and Private medical college and their Total seats Fees statewlse detalls using the dataset available at www.data.gov.in. Also, perform the following operations. (@ To Change the name of the state AP to Andhra. (@ To Count and Display Non-NaN values of each column. G@)_ To Count and Display Non-NaN values of each row. (| To Increase the fees of all colleges by 5% () To Replace all NaN values with 0. CREATING A PYTHON PROGRAM TO DISPLAY THE ATTRIBUTES OF A DATAFRAME AIM: To write a Python program to create a DataFrame using Dictionary of list and display the following attributes of the DataFrame: (i) index (ii) columns (iii) axes (iv) dtypes () shape (vi) dimension (vii) T ‘Degree'[’MBA',"MCA,/M.E',"M.Se], ‘Percent :[90,85,91,76) SAMPLE OUTPUT: # Output for Iterrows() Stu Name Anu Degree ver, Percentage 90 Name! 81, dtype: object 82 StuName Arun Degree MEA Percentage 85 Name: $2, dtype: object 33 ‘StuName Bala Degree ME Percentage 91 Name 83, dtype: ebject se ‘StuNane Charan Degree M.Se Percentage 76 Name: 84, dtype: object ss ‘StuName Mano Degree MEA Percentage 64 Bani 65; ctyper apace! # Output for Iteritems Stu Name si Anu 82 Arun 33 Bala St Charan 85 ‘Mano. Name: Stu Name, dtype: object Degree sl MBA S20 MCA 330 ME St M.S0 S50 MCA Name: Degree, atype: object Percentage a1 90 82 6s. 83 on st 76 ss a8 Name: Percentage, dtype: inté@ To write a Python program to create a panda’s DataFrame called Students for the following table and demonstrate iterrows and iteritems. "Charan" ,"Mano"), "Degree" : "HBA", "HCA" Se" ,"MCA"], "Percentage": (90,85, 91,76,84]) ja", "84", "85")) DP=pd.DataFrame (D, index=["S1" , "2" for (row,values) in DP. iterrows (): print (row) print (values) print()#To print an empty line after each row, for (eol,values) in DP. iteritems (): print (col) print (values) print () CREATING A PYTHON PROGRAM FOR PLOTTING PLOTTING HISTOGRAM AIM: To write a Python program to plot a Histogram for the following class interval or range. Also, give appropriate axes name, title and edege color as ‘red’. SOURCE CODE: [import matplotlib.pyplot as plt rks=[40, 60,55,20,35,70, 60,89,20,,33] lt. title("Maths Marks-Histogram of class XII") Lt.xlabel ("Mark Ranges") t.ylabel ("No.of Students") 1t-hist (Marks bins=[0,33,45, 60,100) ,edgecolor=' red’ Lt. show()

Potrebbero piacerti anche