Class 02
Class 02
September 6, 2024
[2]: x = -5
y = -10
[3]: False
[4]: x != y
[4]: True
[5]: x > y
[5]: True
[6]: x < y
[6]: False
[7]: x >= y
[7]: True
[8]: x <= y
[8]: False
False
1
True
x = 5
y = 10
print("After Swapping")
temp = x
x = y
y = temp
print("x =", x)
print("y =", y)
Before Swapping
x = 5
y = 10
After Swapping
x = 10
y = 5
[15]: a = 5
b = 6
print("Before Swapping")
print("a =", a)
print("b =", b)
a,b = b,a
print("After Swapping")
print("a =", a)
print("b =", b)
Before Swapping
a = 5
2
b = 6
After Swapping
a = 6
b = 5
BEFORE SWAPPING a = 6 b = 5
AFTER SWAPPING a = 5 b = 6
x = 5
y = 2
raise_to_power = lambda x,y : x ** y
print("x raised to y = ", raise_to_power(x,y))
x raised to y = 25
[19]: x = 5
y = 2
a = x**y
print(a)
25
nums = [13,30,40,50]
square_all = list(map(lambda nums : nums ** 2, nums))
print(square_all)
3
print(farenhit_temp)
7537185976320
-7537185976320
[26]: # Concatenation
str1 = "Hello"
str2 = "World"
res = str1 +" "+str2
res
[28]: # slicing
# Python = 012345
text = "Python Language"
4
print(text[1:4])
yth
Python is great
5
[68]: import pandas as pd
data = [1,2,3,4,5]
series = pd.Series(data)
series
[68]: 0 1
1 2
2 3
3 4
4 5
dtype: int64
[70]: data = {'Name': ["John", "Sahana", "Syeda"], 'City': ["California", "New York",␣
↪"London"], "Degree": ['MS', 'MCA', 'MBA']}
df = pd.DataFrame(data)
df
[74]: 9.0
6
[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
↪[85,90,88,78,66,35]}
data = pd.DataFrame(data)
print(data)
[82]: Students
Alice 156
Bob 123
John 163
Name: Score, dtype: int64
[84]: Students
Alice 78.0
Bob 61.5
John 81.5
Name: Score, dtype: float64
[86]: Subject
Math 263
Science 179
Name: Score, dtype: int64
7
[103]: data = {'Date':␣
↪['2022-01-01','2022-01-02','2022-01-01','2022-01-02','2022-01-01'],␣
↪'Product':['A','B','A','B','A'], 'Sales':[100,150,200,120,180]}
data = pd.DataFrame(data)
data
pivottable
[105]: Product A B
Date
2022-01-01 480.0 NaN
2022-01-02 NaN 270.0
[ ]: