rufh 2
rufh 2
On
“Introduction To Python”
KMBA251
DEGREE
(Session: 2024- 2025)
SUBMITTED BY
Satendra Diwakar
(2302721570023)
AFFILIATED TO
DR. A.P.J. ABDUL KALAM TECHNICAL UNIVERSITY (FORMERLY UTTAR
PRADESH TECHNICAL UNIVERSITY), LUCKNOW (FS-
1
LIST OF EXPERIMENTS
Course Code: KMBA 251
Course Title: Introduction to Python
2
15 Write a Pandas program to get the first 3 rows of a given
DataFrame.
Sample Python dictionary data and list labels:
exam_data = {'name': ['Anastasia', 'Dima',
'Katherine', 'James', 'Emily', 'Michael', 'Matthew', 21-22
'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no',
'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
16 Write a Pandas program to create a dataframe and set a 27-28
title or name of the index column.
17 Write a Pandas program to join the two given dataframes 28-29
along rows and assign all data.
18 Write a Pandas program to create the todays date 37
19 Write a Pandas program to convert given datetime to 38-39
timestamp.
20 Write a Pandas program to create a line plot of the
historical stock prices of Alphabet Inc. between two 39-40
specific dates
21 Write a Pandas program to create a histograms plot of 42-43
opening, closing, high, low stock prices of Alphabet Inc.
between two specific dates.
22 Write a python program to demonstrate image processing 50-51
3
1
Time_min = 42
Time_sec = 42
New_Time_sec = Time_min * 60 + Time_sec
print(New_Time_sec)
OUTPUT:
1
2
CODE:
#For Loop:-
n=int(input("Enter any
number")) for i in
range(1,11):
print(n,"x",i,"=",n*i)
OUTPUT:-
2
3
#While Loop:-
n=int(input("Enter any
number")) i=1
while i<11:
print(n,"x",i,"=",n*i
) i=i+1
OUTPUT:
3
4
OUTPUT:
4
5
5
6
6.Write a program in python for a user define function diff which is use to function
diff num?
CODE:
def diff(num1, num2):
# calculate the absolute difference between num1 and
num2 diff = abs(num1 - num2)
# return the result
return diff
# example
usage result =
diff(10, 7)
print("The absolute difference between 10 and 7 is:", result)
OUTPUT:
6
7
File. CODE:
import csv
writer = csv.writer(file)
7
8
reader = csv.reader(file)
header =
next(reader)
header
print(header)
print(row)
OUTPUT:
numbers = [1, 2, 3, 4, 5]
print(list(squares))
OUTPUT:
8
9
CODE: b.
6)]
print(list(sums))
OUTPUT:
numpy. CODE:
import numpy as np
arr =
np.arange(1,11)
print("Array:","arr")
print("Number of dimension:",arr.ndim)
print("Shape:",arr.shape)
print("Size:",arr.size)
print("Data type:",arr.dtype)
print("Maximum value:",arr.max())
print("Minimum value:",arr.min())
print("Sum:",arr.sum())
print("Average:",arr.mean())
OUTPUT:
9
10
OUTPUT:
10
11
11
12
print("Sum_of_elements:",sum_of_elements)
import numpy as
np in_num1 = 10
in_num2 = 11
12
13
OUTPUT:
13
14
14
15
15
16
16. Write a Pandas program to create a dataframe and set a title or name of the
index column.
CODE:
import pandas as pd
# Create a
DataFrame data = {
'Name': ['John', 'Alice', 'Bob'],
'Age': [25, 30, 35],
'City': ['New York', 'London', 'Paris']
}
df = pd.DataFrame(data)
# Display the
DataFrame print(df)
OUTPUT:
16
17
17. Write a Pandas program to join the two given dataframes along rows and assign all
data. CODE:
import pandas as pd
# Create the first
DataFrame data1 = {
'Name' : ['ana', 'andy', 'samara'],
'Age' : [20, 22, 34],
'City' : ['Newyork', 'London', 'Paris']
}
df1 = pd.DataFrame(data1)
data2 = {
'Name' : ['Akanksha', 'Dhruva',
'Rajeev'], 'Age' : [15, 20, 25],
'City' : ['chicago', 'Berlin', 'Tokyo']
}
df2 = pd.DataFrame(data2)
# Join the two DataFrames along rows and assign all data
joined_df = pd.concat([ df1, df2 ])
# Display the joined DataFrame
print(joined_df)
OUTPUT:
17
18
18
19
OUTPUT
20. Write a Pandas program to create a line plot of the historical stock prices of Alphabet
Inc. between two specific dates
CODE:-
import yfinance as yf
import pandas as pd
import matplotlib.pyplot as plt
19
20
20
21
21. Write a Pandas program to create a histograms plot of opening, closing, high, low
stock prices of Alphabet Inc. between two specific dates.
CODE:-
import yfinance as yf
import pandas as pd
import matplotlib.pyplot as plt
21
22
# Call the function with the stock symbol of Alphabet Inc. (GOOGL)
plot_stock_histogram('GOOGL', start_date, end_date)
OUTPUT:-
22
23
23
24
24
25
25