Professional Documents
Culture Documents
Vt-On-mlp-b44-21st October Pandas
Vt-On-mlp-b44-21st October Pandas
In [1]: print(1)
print(2)
print(3)
print(4)
print(5)
1 2 3 4 5 6 7 8
In [ ]: #v1) summ all the value from 1 to number(n),take number n as input from user.
Enter a number :: 3
My summation is :: 6
elif x==0:
print("The number is nothing but zero")
else:
print('The number is negative')
In [39]: even=[]
odd=[]
for i in range(100,200+1):
if i%2==0:
even.append(i)
else:
odd.append(i)
print("The all even number are :: ",even)
print('--------------------------------------------------------------------------
print("The all odd number are ::: ",odd)
The all even number are :: [100, 102, 104, 106, 108, 110, 112, 114, 116, 118,
120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150,
152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182,
184, 186, 188, 190, 192, 194, 196, 198, 200]
----------------------------------------------------------------------------
The all odd number are ::: [101, 103, 105, 107, 109, 111, 113, 115, 117, 119,
121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151,
153, 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183,
185, 187, 189, 191, 193, 195, 197, 199]
In [41]: i=3
while i<10:
print(i)
i=i+1
In [ ]: #1) take 3 diff. value as i/p from user and print only the
# largest number.... ( if else)
In [2]: print(L)
[4, 7, 9, 2, 2, 1, 9]
In [3]: print(type(L))
<class 'list'>
In [6]: print(h)
In [10]: L1
In [15]: L1=[4,5,7,7,7,'car',True,False,8,6,2.3,1]
In [16]: L1
In [20]: L1[2]='Hydrabad'
In [21]: L1
In [23]: L1.append('kolkata')
In [24]: L1
In [25]: L1.append(908)
In [26]: L1
In [27]: L1.pop()
Out[27]: 908
In [28]: L1
In [29]: L1.pop()
Out[29]: 'kolkata'
In [30]: L1
In [32]: # 1) insert()
L1=[4,5,7,7,7,'car',True,False,8,6,2.3,1]
In [34]: L1
In [ ]: # 2) index()
In [35]: L1
In [37]: L1.index(7)
Out[37]: 2
In [41]: # 3) count()
L1.count(7)
Out[41]: 3
In [42]: # 4) remove()
L1
In [43]: L1.remove('kolkata')
In [44]: L1
In [45]: L1
In [49]: L1
In [50]: # 6) sort()
L2=[6,0,2,8]
In [51]: L2.sort()
In [52]: L2
Out[52]: [0, 2, 6, 8]
In [53]: L2
Out[53]: [0, 2, 6, 8]
In [54]: L2.sort(reverse=True)
In [55]: L2
Out[55]: [8, 6, 2, 0]
In [58]: a=['a','f','b','z','l']
In [59]: a.sort()
In [60]: a
In [61]: # 7) reverse()
a=['a','f','b','z','l']
In [62]: a.reverse()
In [63]: a
In [64]: # 8) len()
len(a)
Out[64]: 5
In [68]: # 9) extend()
x=[4,8,9,0]
y=[2,4,5,6]
In [66]: x.extend(y)
In [67]: x
Out[67]: [4, 8, 9, 0, 2, 4, 5, 6]
In [69]: x.append(y)
In [70]: x
In [8]: # 1) Take below two list L1=[2,5,8,9] and L2=[1,1,1,1], now sum two list
# and print a list like this [3,6,9,10],
L1=[2,5,8,9]
L2=[1,1,1,1]
L3=[]
for i in range(len(L2)):
m=L1.pop()
n=L2.pop()
s=m+n
L3.append(s)
L3.reverse()
print("The final ans afte summation is : ",L3)
In [4]: L1=[2,5,8,9]
In [5]: len(L1)
Out[5]: 4
In [ ]: # 2) print only the common element from below given two list....
# [5,2,9,0], and [5,6,2,1]
In [10]: [5,2,9,0]
[5,6,2,1]
L3=[]
for i in [5,2,9,0]:
if i in [5,6,2,1]:
L3.append(i)
print("So, the final common list is :::: ",L3)
In [15]: L=[6,1,0,3,8,9]
L.sort()
print("So, the largest element is :: ",L[-2])
In [ ]: #10-11-2021
#Tuple
In [3]: T
In [5]: T1
In [6]: s={6,6,6,6,3,3,3,1,9,9,9,4}
In [7]: s
Out[7]: {1, 3, 4, 6, 9}
In [16]: t
In [17]: t[3]=100
---------------------------------------------------------------------------
<ipython-input-17-318c3cd81b26> in <module>()
----> 1 t[3]=100
In [14]: t
In [24]: t=(6,8,9,0)
In [25]: t.pop()
---------------------------------------------------------------------------
<ipython-input-25-0a5da13a6539> in <module>()
----> 1 t.pop()
In [22]: t
In [30]: L
Out[30]: [4, 7, 9, 0]
In [31]: print(type(T))
<class 'list'>
In [32]: T=tuple(L)
In [34]: T
Out[34]: (4, 7, 9, 0)
In [35]: print(type(T))
<class 'tuple'>
enter elements:7,2,2,2,2,2
('7', ',', '2', ',', '2', ',', '2', ',', '2', ',', '2')
In [42]: T
In [46]: T.index(9)
---------------------------------------------------------------------------
<ipython-input-46-e0564b2a144f> in <module>()
----> 1 T.index(9)
In [47]: len(T)
Out[47]: 8
In [48]: # 3) count()
T
In [53]: T.count(90)
Out[53]: 0
In [54]: T.remove(4)
---------------------------------------------------------------------------
<ipython-input-54-f949fd54b18e> in <module>()
----> 1 T.remove(4)
In [1]: # 11-11-2021
L1=[1,2,[3,4,5,[6,7,[8,9,0]]]]
In [9]: L1[2][3][2][1]
Out[9]: 9
In [8]: D1
In [10]: D1['name']
Out[10]: 'abc'
In [11]: D1['roll']
Out[11]: 23
In [13]: D1
In [25]: D1
In [27]: D1
In [28]: D1['name']='Tiger'
In [29]: D1
In [31]: D1['age']=21
In [32]: D1
'dept': 'cse/it/ece/mca',
'name': 'Tiger',
'roll': 23}
In [33]: D1['sal']=50000
In [34]: D1
'dept': 'cse/it/ece/mca',
'name': 'Tiger',
'roll': 23,
'sal': 50000}
In [35]: # delete
del D1['age']
In [36]: D1
'name': 'Tiger',
'roll': 23,
'sal': 50000}
The dict is {'address': 'mumbai', 'Pass': True, 'name': 'abcd', 'age': 20, 'ro
ll': 21}
In [39]: print(type(d))
<class 'dict'>
In [40]: st=[]
print("---::: Stack Posh:::----")
n=int(input("Enter the stack size ::: "))
for i in range(n):
v=eval(input("Enter element in the stack :: "))
st.append(v)
print("The stack content after insertion is ---",st)
print('----::: stack pop :::----')
print("The pop element are ::: ")
for i in range(len(st)):
m=st.pop()
print(m)
The stack content after insertion is --- ['car', 'bus', 67, True, 3]
True
67
bus
car
In [3]: df
Out[3]:
age dept name roll
0 21 cse sumit 1
1 20 it ikramul 2
2 23 me rajit 3
3 24 ece ajit 4
In [4]: print(df)
0 21 cse sumit 1
1 20 it ikramul 2
2 23 me rajit 3
3 24 ece ajit 4
In [5]: x=['a','b','c','d']
df=pd.DataFrame({'name':['sumit','ikramul','rajit','ajit'], 'roll':[1,2,3,4],
'age':[21,20,23,24],'dept':['cse','it','me','ece']},index=x)
In [6]: df
Out[6]:
age dept name roll
a 21 cse sumit 1
b 20 it ikramul 2
c 23 me rajit 3
d 24 ece ajit 4
In [7]: df1=df
In [8]: df1['address']=['kol','hyd','ulu','jam']
In [9]: df1
Out[9]:
age dept name roll address
b 20 it ikramul 2 hyd
c 23 me rajit 3 ulu
In [14]: d={'name':'First_name'}
In [15]: df1.rename(columns=d,inplace=True)
In [16]: print(df1)
b 20 it ikramul 2 hyd
c 23 me rajit 3 ulu
In [17]: d={'address':'ADDRESS'}
In [19]: df1.rename(columns=d,inplace=True)
In [20]: df1
Out[20]:
age dept irst_name roll ADDRESS
b 20 it ikramul 2 hyd
c 23 me rajit 3 ulu