0% found this document useful (0 votes)
7 views2 pages

22BS0888 B.Varsini

Uploaded by

varsinivarsini38
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)
7 views2 pages

22BS0888 B.Varsini

Uploaded by

varsinivarsini38
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/ 2

import pandas as pd

data = {0:[2, 3],1: [3, 4]}


df=pd.DataFrame (data)
print (df)
B 1
0 2 3
1 3 4

import pandas as pd
data={"Name':['Alex', 'Banu','John'], 'Age': (35, 25,30]}
df- pd.DataFrame(data)
print (df)

Name
Alex
Banu 2
John

import pandas as pd
import numpy as np
abc={'Distinction':[100,90,
dfepd.n. np.nan, 95], 'First class': [30,45,5,np. nan], 'Second class':[np.nan, 40, 80,98]}
ataFrame (abc)
print (df)

Distinction First class Second class


100.0 30.0 Nab
1 90.¬ 45.0 40.
2 NaN 5.0 80.
3 95.0 NaN 98.e

import pandas as pd
import numpy as np
abc={'Distinction': [98,90, np.nan, 95),'First class':[30,45,5,np.nan], 'Second class': [np.nan, 40, 80, 98]}
df=pd. DataFrame (abc)
df.isnull()

Distinction First class Second class

False False True

False False False

True False False

3 False True False

import pandas as pd

import numpy as np
dict={'First score': [106,90, np.nan, 95],'second score': [30,45, 5, np.nan], 'third score':[np.nan, 40, 80,98])
df=pd.DataFrame (dict)
res=df.fillna(0)
print(res)

First score second score third score


100.0 30.0 0.0
1 90.0 45.0 40.0
2 0.0 5.0 80.0
3 95.0 0.0 98.

import pandas as pd

data={"Category':['A', "8', 'A', 'B', 'A', 'B'], "Value' : (10,20,15, 25, 12, 18])
df=pd.DataFrame (data)
grouped=df.groupby('Category')
values-grouped.mean()
nnintmocieinal DataFrame:" )
print (df)
print("/nGrouped DataFrame:")
print (mean_values)
Original DataFrame:
Category Value
10
1

2 15
3 25
12

5 18
/nGrouped DataFrame:
Value

mdiiuo4onwTEa0-sCCAPa-sKKCR2EloEO0tscrol|To=l 2unz65PvWAnrintMode=true
Category

.A

import pandas as pd
12.333333
21.000000

a=[[2,3), (7, 8]]


df=pd. DataFrame (a )
print('Data Frame:,df)

Data Frame: 1
0 2 3
1 7 8

data={"Category' :['A', '8','A', 'B', "A', "B'], "Value':(10, 20,25,35, 15,40])


df=pd. DataFrame (data)
sum_by_category-df . groupby('Category' )["value'].sum()
print("0riginal DataFrame:")
print (df)
print("\n Sum of 'Value' column for each Category:")
print (sum_by_category)

2 Original DataFrame :
Category Value
1
1

3
15
5 B

Sum of 'Value' column for each Category:


Category
B 95
Name: Value, dtype: int64

import pandas as pd
marke("Category' :['A', 'B', 'A', '8', 'A', "B'], "Value':[10,29,30, 11,28, 14] }
df=pd.DataFrame (mark)
max_by_category=df. groupby( 'Category')['Value']. max()
print("Original DataFrame:")
print(df)
print("\nMaximum value of Value' column for each category:")
print(max_by_category)
Original DataFrame:
Category Value
10
1 9

2 30
11

4 A 28
14

Maximum value of 'Value' column for each category:


Category

B
Name: Value, dtype: int64

import pandas as pd
mark={' category ':['A', 'B', 'A', 'B','A', 'B'], 'Value': [10, 11, 12, 17, 23, 22] )
df=pd.DataFrame (mark)
min_by_category-df.groupby('category')['Value'].min()
print("original DataFrame:")
print (df)
print("\n minimum value of "Value' column for each category:")
print (min_by_category)

Original DataFrame:
category Value

11
12

3 17
4 23
22

minimum value of 'Value' column for each category:


category
A 10

B 11

You might also like