Found 10476 Articles for Python

Python for Spreadsheet Users

Pradeep Elance
Updated on 04-Feb-2020 06:12:44

233 Views

Excel is the most famous spreadsheet and almost every computer user is comfortable with the idea of managing the data through spreadsheets. Eventually some python program has to interact with excel. Many python libraries are available to create, read and write into excel files. We will see the examples of few such important libraries below.Using openpyxlThis library can read/write Excel 2010 xlsx/xlsm/xltx/xltm files. In the below example we create a excel worksheet, assign data to its cells and finally save the file to a desired location. The module has many in-built methods which can be used for this. We see ... Read More

Predicting Customer Churn in Python

Pradeep Elance
Updated on 04-Feb-2020 06:07:21

604 Views

Every business depends on customer's loyalty. The repeat business from customer is one of the cornerstone for business profitability. So it is important to know the reason of customers leaving a business. Customers going away is known as customer churn. By looking at the past trends we can judge what factors influence customer churn and how to predict if a particular customer will go away from the business. In this article we will use ML algorithm to study the past trends in customer churn and then judge which customers are likely to churn.Data PreparationAs an example will consider the Telecom ... Read More

Fraud Detection in Python

Pradeep Elance
Updated on 04-Feb-2020 05:43:44

3K+ Views

Frauds are really in many transactions. We can apply machine learning algorithms to lies the past data and predict the possibility of a transaction being a fraud transaction. In our example we will take credit card transactions, analyse the data, create the features and labels and finally apply one of the ML algorithms to judge the nature of transaction as being fraud or not. Then we will find out the accuracy, precision as well as f-score of the model we are chosen.Preparing the DataWe in this step we read the source data, study the variables present in it and have ... Read More

Fast XML parsing using Expat in Python

Pradeep Elance
Updated on 04-Feb-2020 05:30:44

1K+ Views

Python allows XML data to be read and processed through its inbuilt module called expat. It is a non-validating XML parser. it creates an XML parser object and captures the attributes of its objects into various handler functions. In the below example we will see how the various handler functions can help us read the XML file as well as give the attribute values as the output data. This generated data can be used for the processing.Exampleimport xml.parsers.expat # Capture the first element def first_element(tag, attrs):    print ('first element:', tag, attrs) # Capture the last element def last_element(tag):   ... Read More

Analyzing Census Data in Python

Yaswanth Varma
Updated on 14-Jul-2025 15:33:52

742 Views

Census data is the source of information collected by the government to understand the population and its characteristics. It consists of details such as age, gender, education, and housing. This helps the government in understanding the current scenario as well as planning for the future. In this article, we are going to learn how to analyze the census data in Python. Python, with its libraries like pandas, numpy, and matplotlib, is widely used for analyzing census data. Analyzing Census Data Here, we are going to use the sample data that consists of the census data stored in ... Read More

Maximum Product Subarray in Python

Arnab Chakraborty
Updated on 04-May-2020 08:51:03

1K+ Views

Suppose we have an integer array called nums, we have to find the contiguous subarray within an array (containing at least one number) which has the largest product. So if the array is [2, 3, -2, 4], the output will be 6, as contiguous subarray [2, 3] has max product.To solve this, we will follow these steps −max_list := list of size nums, and fill with 0min_list := list of size nums, and fill with 0max_list[0] := nums[0] and min_list[0] := nums[0]for i in range 1 to length of numsmax_list[i] = max of max_list[i - 1]*nums[i], min_list[i - 1]*nums[i] and ... Read More

Construct Binary Tree from Inorder and Postorder Traversal in Python

Arnab Chakraborty
Updated on 04-May-2020 06:32:22

245 Views

Suppose we have the inorder and postorder traversal sequence of a binary tree. We have to generate the tree from these sequences. So if the postorder and inorder sequences are [9, 15, 7, 20, 3] and [9, 3, 15, 20, 7], then the tree will be −Let us see the steps -Suppose the method is called buildTree with preorder and inorder listsroot := last node from the postorder, and delete first node from postorderroot_index := index of root.val from the inorder listleft or root := buildTree(subset of inorder from root_index + 1 to end, postorder)right or root := buildTree(subset of ... Read More

Construct Binary Tree from Preorder and Inorder Traversal in Python

Arnab Chakraborty
Updated on 04-May-2020 06:27:14

1K+ Views

Suppose we have the inorder and preorder traversal sequence of a binary tree. We have to generate the tree from these sequences. So if the preorder and inorder sequences are [3, 9, 20, 15, 7] and [9, 3, 15, 20, 7], then the tree will be −Let us see the steps −Suppose the method is called buildTree with preorder and inorder listsroot := first node from the preorder, and delete first node from preorderroot_index := index of root.val from the inorder listleft or root := buildTree(preorder, subset of inorder from 0 to root_index)right or root := buildTree(preorder, subset of inorder ... Read More

Word Search in Python

SaiKrishna Tavva
Updated on 14-Oct-2024 14:15:08

6K+ Views

In Python word search refers to determining if a given word exists in the grid, this can be done using various approaches like DFS method and backtracking algorithm, etc, and the given word can be formed by sequentially connecting adjacent cells both horizontally or vertically. Step Involved The steps involved in performing word search in Python are as follows. Consider the input board(2D grid) Define the class ... Read More

Subsets in Python

Arnab Chakraborty
Updated on 04-May-2020 06:14:43

1K+ Views

Suppose we have a set of numbers; we have to generate all possible subsets of that set. This is also known as power set. So if the set is like [1, 2, 3], then the power set will be [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]Let us see the steps −We will solve this using recursive approach. So if the recursive method name is called solve(), and this takes the set of numbers (nums), temporary set (temp), res and indexThe solve() function will work like below −if index = length of nums, then create ... Read More

Advertisements