0% found this document useful (0 votes)
79 views7 pages

Grade 12 - Practical..IP (10 To 15)

This document contains 15 pandas practical problems involving dataframes. The problems include creating a dataframe from ecommerce data and generating descriptive statistics, finding column sums and means, locating the largest values in a dataframe, subtracting row means from elements, replacing negative values with 0, and replacing missing values with 999.

Uploaded by

Milan Laddha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views7 pages

Grade 12 - Practical..IP (10 To 15)

This document contains 15 pandas practical problems involving dataframes. The problems include creating a dataframe from ecommerce data and generating descriptive statistics, finding column sums and means, locating the largest values in a dataframe, subtracting row means from elements, replacing negative values with 0, and replacing missing values with 999.

Uploaded by

Milan Laddha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SNBP INTERNATIONAL SCHOOL & KIDZONE

SENIOR SECONDARY SCHOOL


MORWADI, PIMPRI, PUNE
CBSE AFFILIATION NO. 1130522
ACADEMIC YEAR 2021-2022

Informatics Practices

#Practical no 10
#Create a Data Frame based on ecommerce data and
generate descriptive statistics(mean, mode, median,
quartile,and variance)
import pandas as pd
sales={"InvoiceNo":[1001,1002,1003,1004,1005,1006,1007],

"ProductName":["LED","AC","Deodrant","Jeans","Books","Sh
oes","Jacket"],
"Quantity":[2,1,2,1,2,1,1],
"Price":[65000,55000,500,2500,950,3000,2200] }
df=pd.DataFrame(sales)
print(df["Price"].describe().round(2))
#Output:
#Practical no 11
#Find the sum of each columns, or find the column with the
lowest mean.
import pandas as pd
Profit= { "TCS":{'Qtr1':2500,
"Qtr2":2000,"Qtr3":3000,"Qtr4":2000} ,
"WIPRO":{'Qtr1':2800,
“Qtr2":2400,"Qtr3":3600,"Qtr4":2400},
"L&T": {'Qtr1':2100,
"Qtr2":5700,"Qtr3":35000,"Qtr4":2100}}
df=pd.DataFrame(Profit)
print(df)
print()
print("Column wise sum in dataframe is :::")
print(df.sum(axis=0))
print()
print("Column wise mean value are::::")
print(df.mean(axis=0))
print()
print("Column with minimum mean value is :::")
print(df.mean(axis=0).idxmin())
#output
#Practical no 12
#Locate 3 largest values in a dataframe
import pandas as pd
dict1=
{'Name':['Rahul','Riya','Rohan','Raja'],'Marks':[55,94,75,67],\
'Roll no':[12,34,45,35]}
dmarks=pd.DataFrame(dict1)
print(dmarks)
print(dmarks.nlargest(3,['Marks']))
#Output
#Practical no 13
#Subtract the mean of a row from each element of the row
in a Data Frame.
import pandas as pd
Profit={ "TCS":{'Qtr1':2500,
"Qtr2":2000,"Qtr3":3000,"Qtr4":2000},
"WIPRO":{'Qtr1':2800,
"Qtr2":2400,"Qtr3":3600,"Qtr4":2400},
"L&T": {'Qtr1':2100,
"Qtr2":5700,"Qtr3":35000,"Qtr4":2100}}
df=pd.DataFrame(Profit)
print(df)
print()
print("Mean of each row is ::::")
print(df.mean(axis=1))
print()
print("DataFrame after subtracting mean value of each row
from each element of that row is :::")
print(df.sub(df.mean(axis=1),axis=0))

#Output

#Practical no. 14
#Replace all negative values in a dataframe with a 0
import pandas as pd
dic={"Data1":[-5,-2,5,8,9,-6], "Data2":[2,4,10,15,-5,-8]}
df=pd.DataFrame(dic)
print(df)
print()
print("DataFrame after replacing negative values with 0::")
df[df<0]=0
print(df)

#Output

#Practical no. 15
#Replace all missing values in a dataframe with a 999
import pandas as pd
import numpy as np
dic={"EmpID":[1,2,np.nan,4,5],
"Empname":["Rahul","Rohan","Raj",np.nan,"Ramesh"]}
df=pd.DataFrame(dic)
print(df)
print()

df=df.fillna({"EmpID":999,"Empname":999})
print()
print(df)
#Output

You might also like