Tag Archives: python example

Python Example – Write a Python program to convert an array to an ordinary list with the same items

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to convert an array to an ordinary list with the same items.   Sample Solution: Python Code : from array import * array_num = array(‘i’, [1, 3, 5, 3, 7, 1, 9, 3]) print(“Original array: “+str(array_num)) num_list = array_num.tolist() print(“Convert the …

Python Example – Write a Python program to remove a specified item using the index from an array

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to remove a specified item using the index from an array.   Sample Solution: Python Code : from array import * array_num = array(‘i’, [1, 3, 5, 7, 9]) print(“Original array: “+str(array_num)) print(“Remove the third item form the array:”) array_num.pop(2) print(“New …

Write a program to predict Bank Customer Churn using Decision Tree with Grid Search Cross Validation in Python

(End-to-End Jupyter Notebook for Citizen Data Scientist & Business Analyst) Write a program to predict Bank Customer Churn using Decision Tree with Grid Search Cross Validation in Python. In this end-to-end applied machine learning and data science notebook, the reader will learn: How to predict Bank Customer Churn using Decision Tree with Grid Search Cross …

Python Example – Write a Python program to insert a new item before the second element in an existing array

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to insert a new item before the second element in an existing array.   Sample Solution: Python Code : from array import * array_num = array(‘i’, [1, 3, 5, 7, 9]) print(“Original array: “+str(array_num)) print(“Insert new value 4 before 3:”) array_num.insert(1, …

Python Example – Write a Python program to append items from a specified list

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to append items from a specified list.   Sample Solution: Python Code : from array import * num_list = [1, 2, 6, -8] array_num = array(‘i’, []) print(“Items in the list: ” + str(num_list)) print(“Append items from the list: “) array_num.fromlist(num_list) …

Python Example – Write a Python program to append items to the end of the array

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to append items to the end of the array.   Sample Solution: Python Code : from array import * array_num = array(‘i’, [1, 3, 5, 7, 9]) print(“Original array: “+str(array_num)) array_num.extend(array_num) print(“Extended array: “+str(array_num)) Sample Output: Original array: array(‘i’, [1, 3, …

Python Example – Write a Python program to get the number of occurrences of a specified element in an array

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to get the number of occurrences of a specified element in an array.   Sample Solution: Python Code : from array import * array_num = array(‘i’, [1, 3, 5, 3, 7, 9, 3]) print(“Original array: “+str(array_num)) print(“Number of occurrences of the …

Python Example – Write a Python program to reverse the order of the items in the array

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to reverse the order of the items in the array.   Sample Solution: Python Code : from array import * array_num = array(‘i’, [1, 3, 5, 3, 7, 1, 9, 3]) print(“Original array: “+str(array_num)) array_num.reverse() print(“Reverse the order of the items:”) …

Python Example – Write a Python program to append a new item to the end of the array.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to append a new item to the end of the array.   Sample Solution: Python Code : from array import * array_num = array(‘i’, [1, 3, 5, 7, 9]) print(“Original array: “+str(array_num)) print(“Append 11 at the end of the array:”) array_num.append(11) …

Python Example – Write a Python program to create an array of 5 integers and display the array items

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to create an array of 5 integers and display the array items. Access individual element through indexes.   Sample Solution: Python Code : from array import * array_num = array(‘i’, [1,3,5,7,9]) for i in array_num: print(i) print(“Access first three items individually”) …