Arslonov Siyovush 941-19 guruh talabasi
1-Amaliyot ishi:
2-Amaliyot ishi
3-Amaliyot ishi
4-Amaliyot ishi
5-Amaliyot ishi
12. Тўплам элементларини топинг, агарда
А = {1, 2, 4, 5}; B = {1, 3, 6, 7}; C = {3, 2, 6, 7}.
6-Amaliyot ishi
y = sinx + cosx grafikini chizish
Kodi:
import numpy as np
import matplotlib.pyplot as plt
# Define the x values
x = np.linspace(0, 2*np.pi, 100)
# Compute the y values
y = np.sin(x) + np.cos(x)
# Create a figure and axis
fig, ax = plt.subplots()
# Plot the curve
ax.plot(x, y)
# Add labels and title
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('y = sin(x) + cos(x)')
# Display the plot
plt.show()
Natija:
7-Amaliyot ishi
8-Amaliyot ishi
How to do Fuzzy Matching on Pandas Dataframe Column Using Python?
Kodi:
import pandas as pd
from fuzzywuzzy import fuzz
from fuzzywuzzy import process
# creating the dictionaries
dict1 = {'name': ["aparna", "pankaj", "sudhir",
"Geeku", "geeks for geeks"]}
dict2 = {'name': ["aparn", "arup", "Pankaj",
"for geeks geeks", "sudhir c",
"geeks geeks"]}
# converting to pandas dataframes
dframe1 = pd.DataFrame(dict1)
dframe2 = pd.DataFrame(dict2)
# empty lists for storing the matches
# later
mat1 = []
mat2 = []
p = []
# printing the pandas dataframes
print("First dataframe:\n", dframe1,
"\nSecond dataframe:\n", dframe2)
# converting dataframe column to
# list of elements
# to do fuzzy matching
list1 = dframe1['name'].tolist()
list2 = dframe2['name'].tolist()
# taking the threshold as 80
threshold = 80
# iterating through list1 to extract
# it's closest match from list2
for i in list1:
mat1.append(process.extractOne(
i, list2, scorer=fuzz.partial_ratio))
dframe1['matches'] = mat1
# iterating through the closest matches
# to filter out the maximum closest match
for j in dframe1['matches']:
if j[1] >= threshold:
p.append(j[0])
mat2.append(",".join(p))
p = []
# storing the resultant matches back to dframe1
dframe1['matches'] = mat2
print("\nDataFrame after Fuzzy matching using fuzz.partial_ratio:")
dframe1
Natija:
9-Amaliyot ishi
Restoran taomlari va xizmatlari uchun reytinglarni ko'rsatish uchun Matplotlib yordamida Gauss taqsimotini qanday tuzish
import numpy as np
import matplotlib.pyplot as plt
# Define the mean and standard deviation for food and service ratings
food_mean = 7.5
food_std = 1.5
service_mean = 8.0
service_std = 1.0
# Generate the x-axis values
x = np.linspace(0, 10, 1000)
# Generate the food and service distributions
food_dist = 1 / (food_std * np.sqrt(2 * np.pi)) * np.exp(-0.5 * ((x - food_mean) / food_std)**2)
service_dist = 1 / (service_std * np.sqrt(2 * np.pi)) * np.exp(-0.5 * ((x - service_mean) / service_std)**2)
# Create a figure and axis
fig, ax = plt.subplots()
# Plot the food and service distributions
ax.plot(x, food_dist, color='blue', label='Food')
ax.plot(x, service_dist, color='green', label='Service')
# Add labels and title
ax.set_xlabel('Rating')
ax.set_ylabel('Frequency')
ax.set_title('Restaurant Ratings')
# Add a legend
ax.legend()
# Display the plot
plt.show()
Natija:
Do'stlaringiz bilan baham: |