0% found this document useful (0 votes)
48 views10 pages

Import Pandas As PD

The document demonstrates various operations that can be performed on pandas Series including addition, subtraction, multiplication, division and exponentiation. It shows applying these operations between Series, taking the head and tail of Series, and sorting Series in ascending and descending order.

Uploaded by

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

Import Pandas As PD

The document demonstrates various operations that can be performed on pandas Series including addition, subtraction, multiplication, division and exponentiation. It shows applying these operations between Series, taking the head and tail of Series, and sorting Series in ascending and descending order.

Uploaded by

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

import pandas as pd

dic={1:3,2:4,3:9,4:9}
a=pd.Series(dic)
b=pd.Series([1,2,3,4,5,6,7,8,9,10],index=range(10))
print(a.add(b,fill_value=(10)))
print(a.sub(b,fill_value=(10)))
print(a.mul(b,fill_value=(5)))
print(a.div(b,fill_value=(10)))

OUTPUT:
0 11.0
1 5.0
2 7.0
3 13.0
4 14.0
5 16.0
6 17.0
7 18.0
8 19.0
9 20.0
dtype: float64
0 9.0
1 1.0
2 1.0
3 5.0
4 4.0
5 4.0
6 3.0
7 2.0
8 1.0
9 0.0
dtype: float64
0 5.0
1 6.0
2 12.0
3 36.0
4 45.0
5 30.0
6 35.0
7 40.0
8 45.0
9 50.0
dtype: float64
0 10.000000
1 1.500000
2 1.333333
3 2.250000
4 1.800000
5 1.666667
6 1.428571
7 1.250000
8 1.111111
9 1.000000
dtype: float64
import pandas as pd
a=pd.Series([1,2,3,4,5,6,7],index=['a','b','c','d','e','f','g'])
print(a[:3])
print(a[::3])
print(a[5:])
print(a[3::])
a 1
b 2
c 3
dtype: int64
a 1
d 4
g 7
dtype: int64
f 6
g 7
dtype: int64
d 4
e 5
f 6
g 7
dtype: int64
import pandas as pd
dic={1:3,2:4,3:9,4:9}
a=pd.Series(dic)
b=pd.Series([1,2,3,4,5],index=range(5))
print(b[3])
print(a[3])
print(a[1])
print(b[4])
print(a[1])
runfile('E:/DEVANSHU PYTHON/pq5.py', wdir='E:/DEVANSHU PYTHON')
4
9
3
5
3

import pandas as pd
dic={1:3,2:4,3:9,4:9}
a=pd.Series(dic)
b=pd.Series([1,2,3,4,5],index=range(5))
print(a)
print(b)
print(a+b)
print(b+a)
print(a-b)
print(b-a)
print(b/a)
print(b*a)
print(a**b)
runfile('E:/DEVANSHU PYTHON/pq1.py', wdir='E:/DEVANSHU PYTHON')
1 3
2 4
3 9
4 9
dtype: int64
0 1
1 2
2 3
3 4
4 5
dtype: int64
0 NaN
1 5.0
2 7.0
3 13.0
4 14.0
dtype: float64
0 NaN
1 5.0
2 7.0
3 13.0
4 14.0
dtype: float64
0 NaN
1 1.0
2 1.0
3 5.0
4 4.0
dtype: float64
0 NaN
1 -1.0
2 -1.0
3 -5.0
4 -4.0
dtype: float64
0 NaN
1 0.666667
2 0.750000
3 0.444444
4 0.555556
dtype: float64
0 NaN
1 6.0
2 12.0
3 36.0
4 45.0
dtype: float64
0 NaN
1 9.0
2 64.0
3 6561.0
4 59049.0
dtype: float64
import pandas as pd
dic={1:3,2:4,3:9,4:9}
a=pd.Series(dic)
b=pd.Series([1,2,3,4,5],index=range(5))
print(a*a)
print(a**2)
print(b*b)
print(b**2)
runfile('E:/DEVANSHU PYTHON/pq3.py', wdir='E:/DEVANSHU PYTHON')
1 9
2 16
3 81
4 81
dtype: int64
1 9
2 16
3 81
4 81
dtype: int64
0 1
1 4
2 9
3 16
4 25
dtype: int64
0 1
1 4
2 9
3 16
4 25
dtype: int64
import pandas as pd
dic={1:3,2:4,3:9,4:9}
a=pd.Series(dic)
b=pd.Series([1,2,3,4,5],index=range(5))
print(pd.head())
print(pd.tail())
print(pd.head(3))
print(pd.tail(5))
print(pd.head(3))
print(pd.tail(3))
runfile('E:/DEVANSHU PYTHON/pq5.py', wdir='E:/DEVANSHU PYTHON')
5 3
6 4
7 3
8 2
9 6
dtype: int64
0 9
1 8
2 7
3 4
4 5
dtype: int64
0 9
1 8
2 7
dtype: int64
5 3
6 4
7 3
8 2
9 6
dtype: int64
0 9
1 8
2 7
dtype: int64
7 3
8 2
9 6
dtype: int64
import pandas as pd
a=pd.Series([9,8,7,4,5,3,4,3,2,6])
a_dsc=a.sort_values(ascending=False)
print(a_dsc)
import pandas as pd
a=pd.Series([9,8,7,4,5,3,4,3,2,6])
a_dsc=a.sort_index(ascending=False)
print(a_dsc)
import pandas as pd
a=pd.Series([9,8,7,4,5,3,4,3,2,6])
a_dsc=a.sort_index()
print(a_dsc)

runfile('E:/DEVANSHU PYTHON/pq3.py', wdir='E:/DEVANSHU PYTHON')


1 9
2 16
3 81
4 81
dtype: int64
1 9
2 16
3 81
4 81
dtype: int64
0 1
1 4
2 9
3 16
4 25
dtype: int64
0 1
1 4
2 9
3 16
4 25
dtype: int64

runfile('E:/DEVANSHU PYTHON/untitled0.py', wdir='E:/DEVANSHU PYTHON')


0 9
1 8
2 7
3 4
4 5
5 3
6 4
7 3
8 7
9 6
dtype: int64

print(a)
0 9
1 8
2 7
3 4
4 5
5 3
6 4
7 3
8 7
9 6
dtype: int64

runfile('E:/DEVANSHU PYTHON/untitled0.py', wdir='E:/DEVANSHU PYTHON')


0 9
1 8
2 7
3 4
4 5
5 3
6 4
7 3
8 2
9 6
dtype: int64
0 True
1 True
2 True
3 True
4 True
5 False
6 True
7 False
8 False
9 True
dtype: bool

print((a**2)
Cell In[5], line 1
print((a**2)
^
SyntaxError: incomplete input

runfile('E:/DEVANSHU PYTHON/untitled0.py', wdir='E:/DEVANSHU PYTHON')


0 9
1 8
2 7
3 4
4 5
5 3
6 4
7 3
8 2
9 6
dtype: int64
0 True
1 True
2 True
3 True
4 True
5 False
6 True
7 False
8 False
9 True
dtype: bool
0 9
1 8
2 7
3 4
4 5
6 4
9 6
dtype: int64

runfile('E:/DEVANSHU PYTHON/untitled1.py', wdir='E:/DEVANSHU PYTHON')


0 9
1 8
2 7
3 4
4 5
5 3
6 4
7 3
8 2
9 6
dtype: int64

runfile('E:/DEVANSHU PYTHON/untitled1.py', wdir='E:/DEVANSHU PYTHON')


0 9
1 8
2 7
3 4
4 5
5 3
6 4
7 3
8 2
9 6
dtype: int64

runfile('E:/DEVANSHU PYTHON/untitled2.py', wdir='E:/DEVANSHU PYTHON')


9 6
8 2
7 3
6 4
5 3
4 5
3 4
2 7
1 8
0 9
dtype: int64

runfile('E:/DEVANSHU PYTHON/untitled3.py', wdir='E:/DEVANSHU PYTHON')


0 9
1 8
2 7
9 6
4 5
3 4
6 4
5 3
7 3
8 2
dtype: int64

runfile('E:/DEVANSHU PYTHON/untitled3.py', wdir='E:/DEVANSHU PYTHON')


8 2
5 3
7 3
3 4
6 4
4 5
9 6
2 7
1 8
0 9
dtype: int64

You might also like