Vasishtha Genesis School: Name: Roll STD: - Sub: - Aayush Shah No.: - 01 B IP Year 2023-24 Academic

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 14

Vasishtha

Genesis School

Practical File

Name: - AAYUSH SHAH


Roll No.: - 01
STD: - 12th B
Sub: - IP
Academic year 2023-24
1. Create a pandas series from dictionary of values.
Input:
import pandas as pd
dict = {'a': 1,'b': 2,'c': 3,'d': 4,'e': 5}
series = pd.Series(dict) print(series)
Output:

a 1
b 2
c 3
d 4
e 5
dtype: int64

2. Create
pandas series from nd.array.
Input:
import pandas as pd import
numpy as np
arr = np.array(['A','B','C','D','E','F'])
series = pd.Series(arr)
print(series)
Output:
0 A
•B
•C
•D
•E
•F dtype: object
3. Given a series, print all element tshat are above the 75th
percentile.
Input:
import pandas as pd import numpy as np
s=pd.Series(np.array([1,2,3,4,5,6,7,8,9])) print(s)
res=s.quantile(q=0.75)
print('The element that are above the 75th percentile::') print(s[s>res])
Output:

0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
dtype: int32
The element that are above the 75th percentile:: 7 8
8 9
dtype: int32
4. To create a series to store 5 students
percentage using dictionary and print all the
element that are above 75
percentage.
Input:
Import pandas as pd
D =(“Arun”:65,”Bala”:91,”Charan:74,”Dinesh”:80)
S=pd.Series(D)
Print(s[s>75])
Output:
Bala 91
Dinesh 80 dtype: int64
5. Creating a series using scalar values.
Input:
Import pandas as pd
Budget=pd.Series(50000,index=[‘Qtr’,’Qtr2’,’Qtr3’])
print(budget)
Output:
Qtr1 50000
Qtr2 50000
Qtr3 50000
dtype: 50000
6. Creating a series
using numpy array
Input:
import pandas as pd import numpy as np
section=[‘A’,’B’,’C’]
Contribution=np.array([6700,5500,np.NaN])
S=pd.Series(data=contribution,index=section)
Print(S)
Output:
A 6700.0
B 5500.0
C NaN
dtype: float64
7. Create a dataframe using
Input: nested list
Import pandas as pd L=[[‘Arun’,21],[‘Bala’,23],
[‘csharan’,22]]
D=pd.DataFrame(L,index=[‘stu1’,‘stu2’,‘stu3’] Print(D)
Output:
8. Filtering data in data frame Input:
Import pandas as pd D=(‘stu_Name’:
[‘Anu’,’Arun’,’Bala’,’Charan’,’Mano’ ],
‘degree’:[‘MBA’,’MCA’,’M.E’,’M.Sc’,’MCA’]
‘percentage’:[90,85,91,76,84])
DF=pd.DataFrame(D,index=[‘s1’,’s2’,’s3’,’s4’,s5’])
Print(DF.loc[DF[‘Percentage’]>85])
Output:

9. Locating 3 lagrest values in datarame


Imput:
import pandas as pd data={'Name':
['Aman','Rohit','Deepika','Kamal','Deva','Ramesh','Adnan'], 'Sales':
[8500,4500,9300,8600,9200,9600,8400]}
sales=pd.DataFrame(data) print(sales.nlargest(3,['Sales']))
Output:
Name Sales

5 Ramesh 9600
2 Deepika 9300
4 Deva 9200
10. Replacing all negative values with 0 Input:
import pandas as pd
data = {'sales1':[10,20,-4,5,-1,15],
'sales2':[20,15,10,-1,12,-2]}
df = pd.DataFrame(data)
print("Data Frame") print(df)
print('Display DataFrame after replacing every negative value with 0')
df[df<0]=0
print(df)
Output:
Data Frame Display DataFrame after
sales1 sales2 replacing every negative value
0 10 20 with 0
1 20 15 sales1 sales2
2 -4 10 20 0 10
3 5 -1 15 1 20
4 -1 12 2 10
0
5 15 -2 3 50
4 0 12

11. Plotting line chart Input:


import matplotlib.pyplot as pp
day =['Monday','Tuesday','Wednesday','Thursday','Friday'] dr =
[450,560,400,605,580]
fd = [490,600,425,610,625]
pp.plot(day,dr,label='Drinks',color='g',linestyle='dotted',marker='+')
pp.plot(day,fd,label='Food',color='m',linestyle='dashdot',marker='x')
pp.title("The Weekly Restaurant Orders")
pp.xlabel("Days") pp.ylabel("Orders") pp.legend() pp.show()
Output:

12. Plotting a bar graph


Input:
import matplotlib.pyplot as pp overs
=[1,2,3,4]runs=[6,18,10,5]
pp.bar(overs,runs,color='m') pp.xlabel('Overs')
pp.xlabel('Runs') pp.title('Bowling Spell Analysis')
pp.xticks([1,2,3,4])
pp.yticks([5,10,15,20]) pp.show()

Output:

13. Plotting a line chart Input:


import matplotlib.pyplot as pp
day =['Monday','Tuesday','Wednesday','Thursday','Friday'] inc =
[510,350,475,580,600]
pp.plot(day,inc,label='Income',color='r',linestyle='dashed',marker='D')
pp.title("The Weekly Income Report")
pp.xlabel("Days") pp.ylabel("Income") pp.legend() pp.show()
Output:

14. Plotting a bar graph Input:


import matplotlib.pyplot as plt activities = ['eat', 'sleep', 'work', 'play']
slices = [3, 7, 8, 6]
colors = ['r', 'y', 'g', 'b'] plt.pie(slices, labels = activities, colors=colors,
startangle=90, shadow = True, explode = (0, 0, 0.1, 0), radius = 1.2,
autopct = '%1.1f%%')
plt.legend() plt.show()

Output:
Q2 create the following table named ‘student ‘ with appropriate data
type ,size and constraint(s) if any
Q4 display all the information of males whose city is neither delhi or
Mumbai
Q5 diplay the details of all the students whose date of birth is after
nishant’s birth date 1995-12 -06

Q7 display all columns arranged in descending order of city and within


the city in the ascending order their marks
Q8 list names of all students whose name has the character ‘a’

Q 10 display avg marks , highest marks and total no of students for each class
Q11. Display total no of males and females separately ,along with their avg
marks

Q.12 increase the marks of 10th class students by 5% marks

Q.13 add new column named address


Q.14 Add primary key to the column name

You might also like