Professional Documents
Culture Documents
Certificate
Certificate
Certificate
CERTIFICATE
ROLL NO .: 237802
EXAM NO.: 237802
External Examiner
INDEX
Program :
Output :
Explanation :
The print() function prints the specified message and output on the screen.
Program :
age=20
name='abc'
fav_col='red'
print('AGE:',age)
print('Name:',name)
print('Favourite
colour:',fav_col)
Output :
Explanation :
In the above Program code,
Variable age has Integer Data Type which stores Age.
Variable name has String Data Type which stores Name.
Variable fav_col has String Data Type which stores Favourite Colour.
Aim : Use pandas to create a simple DataFrame with some sample data.
Program :
import pandas as pd data={'Name':['abc','def','ghi'], 'age':
[19,20,21],
'city':['kk','ghansoli','Panvel']}
df=pd.DataFrame(data)
df
Output :
Explanation :
In the above Program code,
We import Library Panda .
We create dictionary of sample data as ‘data’ and the convert it into the
dataframe using the function DataFrame()
Aim : Create a small dataset with missing values using pandas and
display it.
Program :
import pandas as
pd import numpy
as np data = {
'Name': ['Omkar', 'Sid', 'Vaibhav', 'DK'],
'Age': [22, None, 22, 28],
'City': ['Mumbai', 'Pune', None, 'Navi Mumbai'],
'Salary': [50000,75000, None, 55000]
}
df = pd.DataFrame(data)
df
Output :
Output :
Explanation :
In the above Program of code,
for loop is used for iterations
Aim : Create a DataFrame with duplicate rows and remove them using
pandas.
Program :
import pandas as pd data={'Name':
['omkar','yash','DK','vaibhav'],
'age':[20,21,20,21],
'city':['Ghansoli','Dombivali','Airoli','koparkhairane']}
df=pd.DataFrame(data)
print('Original DataFrame:')
print(df)
Output :
Explanation :
In the above example,
We create a DataFrame with duplicate rows based on the ‘Name’,’Age’ and
‘City’ columns
Aim : Plot a basic line graph showing the population growth over years.
Program :
import matplotlib.pyplot as plt
years=[2018,2019,2020,2021,2022]
population=[7.1,6.4,7.8,8.3,7.5]
plt.plot(years,population,marker='o',linestyle='-')
plt.xlabel('Year')
plt.ylabel('population(billions)')
plt.title('population growth over years')
plt.grid(True)
plt.show()
Output :
Then use plt.plot() to create a line graph, where we plot years on the x-
axis and population on y-axis , we use marker= ‘o’ to add markers at data
points and linestyle= ‘-’ to connect the markers with lines. Then add labels
x and y-axis,
Program :
import matplotlib.pyplot as plt
products=['product A','product B','product C', 'product D']
sales=[2000,6700,3590,1200]
plt.bar(products,sales)
plt.xlabel('Products')
plt.ylabel('sales(units)')
plt.title('Sales of different products')
plt.xticks()
plt.tight_layout()
plt.show()
Output :
Program :
import matplotlib.pyplot as plt
variable1=[1,2,3,4,5,6,7,8,9,10]
variable2=[2,3,5,7,11,13,17,19,23,29]
plt.scatter(variable1,variable2,label='Data points',color='blue',marker='o')
plt.xlabel('Variable 1')
plt.ylabel('Variable 2')
plt.title('Scatter plot of Variable 1 vs. Variable 2')
plt.legend()
plt.grid(True)
plt.show()
Output:
Program :
import seaborn as sns
import matplotlib.pyplot as plt
exam_score=[78,85,90,88,92,75,82,95,88,76,89,93,80]
sns.boxplot(x=exam_score,color="lightblue")
plt.ylabel('Exam scores')
plt.title('Box plot of exam scores')
plt.grid(axis='y',linestyle='-',alpha=0.7)
plt.show()
Program :
plt.xlabel('Variable 1')
plt.ylabel('Variable 2')
plt.title('Scatter Plot of Variable 1 vs. Variable 2')
plt.grid(True)
plt.show()
Output :
import matplotlib.pyplot as plt: This line imports the Matplotlib library, which
is used for creating various types of plots and visualisations.
variable1 and variable2: These are two Python lists containing the values of
'Variable 1' and 'Variable 2.' Each list represents a set of data points. In this
example, 'Variable 1' has values 1 through 10, and 'Variable 2' contains a
different set of prime numbers.
variable1 and variable2: These parameters specify the data to be plotted on the x
and y axes, respectively. In this case, 'Variable 1' is on the x-axis, and 'Variable
2' is on the y-axis.
color='blue': This sets the color of the scatter points to blue.
marker='o': This specifies that circular markers (dots) should be used for the
data points.
plt.xlabel('Variable 1') and plt.ylabel('Variable 2'): These lines set labels for
the x and y axes, indicating that 'Variable 1' is on the x-axis and 'Variable 2' is
on the y-axis.
plt.title('Scatter Plot of Variable 1 vs. Variable 2'): This line sets the title of the
plot to "Scatter Plot of Variable 1 vs. Variable 2."
plt.grid(True): This command adds a grid to the plot to help in reading and
interpreting the data points.
plt.show(): This line displays the scatter plot on the screen. It's necessary to
include this line to visualise the plot.
Aim : Calculate and visualise the mean and median of a dataset using pandas
Matplotlib.
Program :
import pandas as pd
import numpy as np
data = {'Values': [12, 24, 36, 48, 60, 72, 84, 96, 108, 120]}
df = pd.DataFrame(data) mean_value
= df['Values'].mean()
median_value = df['Values'].median()
print(f"Mean: {mean_value}")
print(f"Median: {median_value}")
plt.figure(figsize=(8, 6))
plt.legend()
plt.grid(True)
plt.show()
Explanation :
import pandas as pd: Imports the Pandas library for data manipulation.
import numpy as np: Imports the NumPy library for numerical operations.
Sets up a Matplotlib figure with a specific size (8 inches wide and 6 inches
high) using plt.figure(figsize=(8, 6)).
Adds two scatter points to the plot to mark the mean and median:
Sets the title of the plot to 'Box Plot with Mean and Median' with plt.title('Box
Plot with Mean and Median').
Adds a legend to the plot to distinguish the mean and median markers using
plt.legend().
plt.show().
Aim :Choose a small dataset and create a bar chart to show different categories.
Program :
import pandas as pd
data = {
df = pd.DataFrame(data)
plt.figure(figsize=(8, 6))
plt.xlabel('Product')
plt.ylabel('Sales')
plt.title('Product Sales')
plt.xticks(rotation=15)
plt.show()
Explanation :
import pandas as pd: Imports the Pandas library for data manipulation.
Create a dictionary 'data' with two columns: 'Product' and 'Sales,' representing
the product names and their corresponding sales values.
Set the title of the plot to 'Product Sales' using plt.title('Product Sales').
Enable gridlines on the y-axis with a dashed line style and a transparency level
of 0.7 using plt.grid(axis='y', linestyle='--', alpha=0.7).
Aim :Plot a line graph showing the temperature variation over days.
Program :
import pandas as pd
days = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5']
plt.figure(figsize=(8, 6))
markersize=8)
plt.xlabel('Days')
plt.ylabel('Temperature (°F)')
plt.grid(True)
plt.show()
Explanation :
import matplotlib.pyplot as plt: Imports the Matplotlib library for creating plots.
import pandas as pd: Imports the Pandas library for data manipulation.
days: A list of strings representing the days, from 'Day 1' to 'Day 5'.
Set up a Matplotlib figure with a specific size (8 inches wide and 6 inches high)
using plt.figure(figsize=(8, 6)).
points. linestyle='-' specifies that the line connecting the data points should
be solid. color='b' sets the color of the line and markers to blue.
Set the title of the plot to 'Temperature Variation Over Days' using
plt.title('Temperature Variation Over Days').