(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to create a tuple with different data types. Sample Solution: Python Code: # Create a tuple with different data types tuplex = (“tuple”, False, 3.2, 1) print(tuplex) Sample Output: (‘tuple’, False, 3.2, 1) Write a Python program to create …
Day: March 2, 2021
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to create a tuple. Sample Solution: Python Code: # Create an empty tuple x = () print(x) # Create an empty tuple with tuple() function built-in Python tuplex = tuple() print(tuplex) Sample Output: () () Write a Python program to …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to filter a dictionary based on values. Sample Solution: Python Code: marks = {‘Cierra Vega’: 175, ‘Alden Cantrell’: 180, ‘Kierra Gentry’: 165, ‘Pierre Cox’: 190} print(“Original Dictionary:”) print(marks) print(“Marks greater than 170:”) result = {key:value for (key, value) in marks.items() …
(End-to-End Jupyter Notebook for Citizen Data Scientist & Business Analyst) Write a program to predict mobile price using Decision Tree with Grid Search CV in Python. In this end-to-end applied machine learning and data science notebook, the reader will learn: How to predict mobile price using Decision Tree with Grid Search CV in Python. …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to drop empty Items from a given Dictionary. Sample Solution: Python Code: dict1 = {‘c1’: ‘Red’, ‘c2’: ‘Green’, ‘c3’:None} print(“Original Dictionary:”) print(dict1) print(“New Dictionary after dropping empty items:”) dict1 = {key:value for (key, value) in dict1.items() if value is not …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to match key values in two dictionaries. Sample Solution: Python Code: x = {‘key1’: 1, ‘key2’: 3, ‘key3’: 2} y = {‘key1’: 1, ‘key2’: 2} for (key, value) in set(x.items()) & set(y.items()): print(‘%s: %s is present in both x and …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to replace dictionary values with their average. Sample Solution: Python Code: def sum_math_v_vi_average(list_of_dicts): for d in list_of_dicts: n1 = d.pop(‘V’) n2 = d.pop(‘VI’) d[‘V+VI’] = (n1 + n2)/2 return list_of_dicts student_details= [ {‘id’ : 1, ‘subject’ : ‘math’, ‘V’ : …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to create a dictionary from two lists without losing duplicate values. Sample Solution: Python Code: from collections import defaultdict class_list = [‘Class-V’, ‘Class-VI’, ‘Class-VII’, ‘Class-VIII’] id_list = [1, 2, 2, 3] temp = defaultdict(set) for c, i in zip(class_list, id_list): …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to sort Counter by value. Sample Solution: Python Code: from collections import Counter x = Counter({‘Math’:81, ‘Physics’:83, ‘Chemistry’:87}) print(x.most_common()) Sample Output: [(‘Chemistry’, 87), (‘Physics’, 83), (‘Math’, 81)] Write a Python program to sort Counter by value Free Machine Learning …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to count number of items in a dictionary value that is a list. Sample Solution: Python Code: dict = {‘Alex’: [‘subj1’, ‘subj2’, ‘subj3’], ‘David’: [‘subj1’, ‘subj2’]} ctr = sum(map(len, dict.values())) print(ctr) Sample Output: 5 Write a Python program to …