Best Python code snippet using autotest_python
Mall Customer Segmentation Data.py
1#!/usr/bin/env python2# coding: utf-83# In[3]:4## For data manupilation5import numpy as np6import pandas as pd7# For os8import os9# remove warning10import warnings11warnings.filterwarnings("ignore")12# In[4]:13os.chdir("D:\\data analyst data\\download data\\Mall Customer Segmentation Data")14os.listdir()15# In[5]:16df = pd.read_csv('Mall_Customers.csv')17df.head() 18# In[6]:19df.isnull().sum() # checking if there is any null value 20# In[7]:21df.rename(columns= {'Annual Income (k$)' : 'Annual_Income', 'Spending Score (1-100)' : 'Spending_Score'}, inplace = True)22# In[8]:23df.drop('CustomerID', axis = 1 ,inplace = True)24# In[9]:25df.dtypes # checking data type 26# In[10]:27df.shape #checking shape of data 28# In[11]:29df.columns.values #checking columns 30# In[12]:31# For creating colormaps32import matplotlib.pyplot as plt33import seaborn as sns34# for clustering 35from sklearn.cluster import KMeans36import time # Measuring process time37from sklearn.preprocessing import StandardScaler # For data processing38from sklearn.model_selection import train_test_split39from sklearn.tree import DecisionTreeClassifier as dt40# In[13]:41np.min(df.Age), np.max(df.Age)42# In[14]:43sns.distplot(df.Age) # diagrams 44# In[15]:45sns.distplot(df.Annual_Income, hue = 'Gender')46# In[ ]:47sns.distplot(df.Spending_Score)48# In[16]:49sns.jointplot(df.Age, df.Spending_Score)50# In[17]:51sns.jointplot(df.Annual_Income, df.Age , kind="kde")52# In[18]:53sns.jointplot(df.Annual_Income, df.Age , kind="hex")54# In[19]:55sns.jointplot(df.Annual_Income, df.Age , kind="reg")56# In[20]:57cust_group = df.groupby(['Gender','Age']).sum().reset_index()58cust_group59# In[21]:60df['Annual_Income'].min()61# In[22]:62df['Annual_Income'].max()63# In[23]:64df['Annual_Income_cat'] = pd.cut(65 df['Annual_Income'],66 bins = 3,67 labels= ['low', 'medium','high']68 )69df70# In[24]:71plt.figure(1 , figsize = (10 , 10))72sns.barplot(x = 'Annual_Income_cat', y = 'Age',hue = 'Gender', data = df, )73# In[25]:74plt.figure(figsize=(15,3))75sns.barplot(data=cust_group,x='Age',y='Spending_Score',hue='Gender')76# In[26]:77sns.pairplot(data=cust_group, hue='Gender')78# In[27]:79df.drop(columns=['Annual_Income_cat'],inplace= True) #Dropping columns not needed80# In[28]:81df82# In[29]:83from sklearn.preprocessing import LabelEncoder as le84enc=le()85# In[31]:86df['Gender']=enc.fit_transform(df['Gender'])87df.head()88# In[32]:89find_cls=[]90for i in range(1,15):91 kmean = KMeans(n_clusters=i)92 kmean.fit(df)93 find_cls.append(kmean.inertia_)94# In[33]:95find_cls96# In[34]:97fig, axs = plt.subplots(figsize=(12,5))98sns.lineplot(range(1,15),find_cls, ax=axs,marker='X')99axs.axvline(5, ls="--", c="crimson") # CRIMSON is color, ls - line style100axs.axvline(6, ls="--", c="crimson")101plt.grid() # square lines in back ground102plt.show103# In[35]:104kmean=KMeans(n_clusters=5) # we found that best clusters are 5105kmean.fit(df)106# In[36]:107kmean.inertia_108# In[37]:109kmean.cluster_centers_110# In[38]:111clust_centers=kmean.cluster_centers_112# In[39]:113df.head()114# In[40]:115kmean.labels_116# In[41]:117df['center_cluster']=kmean.labels_118# In[42]:119df120# In[47]:121fig,(ax1,ax2)=plt.subplots(nrows=1, ncols=2,figsize=(15,5))122sns.scatterplot(data = df, x = 'Age', y = 'Spending_Score', ax=ax1, hue = 'center_cluster',palette='Set1') # good color use palette =1123sns.scatterplot(data = df, x='Annual_Income', y ='Spending_Score', ax=ax2, hue='center_cluster',palette='Set1')124# In[344]:125fig,(ax1,ax2)=plt.subplots(nrows=1, ncols=2,figsize=(15,5))126ax1.scatter(kmean.cluster_centers_[:,1], kmean.cluster_centers_[:,3],marker='X',color='red') 127ax2.scatter(kmean.cluster_centers_[:,2], kmean.cluster_centers_[:,3],marker='X',color='red')128# In[ ]:129# In[178]:130# Copy 'Age' column to another variable and then drop it131# We will not use it in clustering132y = df['Age'].values133df.drop(columns = ['Age'], inplace = True)134# In[179]:135y...
student_module.py
Source: student_module.py
...35 def cal_result(self):36 self.total = self.java + self.php + self.python + self.nodejs37 self.percentage = self.total / 438 # find class39 def find_cls(self):40 if self.java < 35 or self.php < 35 or self.python < 35 or self.nodejs < 35:41 self.cls = "Fail"42 elif self.percentage >= 70:43 self.cls = "Distinction"44 elif self.percentage >= 60:45 self.cls = "1st Class"46 elif self.percentage >= 50:47 self.cls = "2nd Class"48 elif self.percentage >= 40:49 self.cls = "3rd Class"50 else:51 self.cls = "Pass Class"52# main method53if __name__ == "__main__":54 obj = Student()55 obj.get_stud(1, "hitesh", "malegaon", 54, 54, 35, 65)56 obj.cal_result()57 obj.find_cls()58 obj.display_stud()59 # objs = [Student() for i in range(3)]60 # for obj in objs:61 # obj.get_Student()62 # for obj in objs:63 # obj.cal_result()64 # obj.find_cls()...
1_6_classes_childes_1.py
Source: 1_6_classes_childes_1.py
...4# <Ð¸Ð¼Ñ ÐºÐ»Ð°ÑÑа 1> : <Ð¸Ð¼Ñ ÐºÐ»Ð°ÑÑа 2> <Ð¸Ð¼Ñ ÐºÐ»Ð°ÑÑа 3> ... <Ð¸Ð¼Ñ ÐºÐ»Ð°ÑÑа k>5# ÐÑо ознаÑаеÑ, ÑÑо клаÑÑ 1 оÑнаÑледован Ð¾Ñ ÐºÐ»Ð°ÑÑа 2, клаÑÑа 3, и Ñ. д.6# ÑловаÑÑ Ð½Ð°Ñледник : пÑедки7child_parents_dict = {}8def find_cls(a, b):9 if a == b:10 return True11 elif a in child_parents_dict[b]:12 return True13 else:14 for c in child_parents_dict[b]:15 if find_cls(a, c):16 return True17 return False18for i in range(int(input())):19 inp = str(input()).split()20 child_parents_dict.update({inp[0]: set(inp[2:])})21for i in range(int(input())):22 inp = (str(input()).split())23 cls1, cls2 = inp[0], inp[1]24 if find_cls(cls1, cls2):25 print("Yes")26 else:...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!