Professional Documents
Culture Documents
Vasishtha Genesis School: Name: Roll STD: - Sub: - Aayush Shah No.: - 01 B IP Year 2023-24 Academic
Vasishtha Genesis School: Name: Roll STD: - Sub: - Aayush Shah No.: - 01 B IP Year 2023-24 Academic
Vasishtha Genesis School: Name: Roll STD: - Sub: - Aayush Shah No.: - 01 B IP Year 2023-24 Academic
Genesis School
Practical File
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:
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
Output:
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
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