Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Python Articles
Page 25 of 855
Predicting Customer Churn in Python
Customer churn refers to customers leaving a business. Predicting churn helps businesses identify at-risk customers and take preventive actions. This article demonstrates how to build a machine learning model to predict telecom customer churn using Python. Dataset Overview We'll use the Telecom Customer Churn dataset which contains customer information like demographics, services, and churn status. Let's load and examine the data ? import pandas as pd # Loading the Telco-Customer-Churn.csv dataset # Dataset available at: https://www.kaggle.com/blastchar/telco-customer-churn data = pd.read_csv('Telecom_customers.csv') print("Dataset shape:", data.shape) print("First few rows:") print(data.head()) The output shows the dataset structure ? ...
Read MoreFraud Detection in Python
Fraud detection is a critical application of machine learning where we analyze historical transaction data to predict whether a new transaction is fraudulent. In this tutorial, we'll build a fraud detection system using credit card transaction data, applying a decision tree classifier to identify suspicious transactions. Preparing the Data We start by loading and exploring our dataset to understand its structure and features. The credit card fraud dataset contains anonymized features (V1-V28) obtained through PCA transformation, along with Time, Amount, and Class columns ? import pandas as pd # Load the credit card dataset # ...
Read MoreFast XML parsing using Expat in Python
Python's xml.parsers.expat module provides fast XML parsing using the Expat library. It is a non-validating XML parser that creates an XML parser object and captures XML elements through various handler functions. This event-driven approach is memory-efficient and suitable for processing large XML files. How Expat Parser Works The Expat parser uses three main handler functions ? StartElementHandler − Called when an opening tag is encountered EndElementHandler − Called when a closing tag is encountered CharacterDataHandler − Called when character data between tags is found Example Here's how to parse XML data using Expat ...
Read MoreWindows registry access using Python (winreg)
Python provides excellent support for OS-level programming through its extensive module library. The winreg module allows Python programs to access and manipulate the Windows registry, which stores configuration settings and system information. The Windows registry is organized in a hierarchical structure with keys and values. Python's winreg module provides functions to connect to, read from, and write to registry keys. Basic Registry Access First, import the winreg module and establish a connection to the registry ? import winreg # Connect to the registry access_registry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) # Open a specific key access_key ...
Read MorePython - Filter the negative values from given dictionary
As part of data analysis, we often encounter scenarios where we need to filter out negative values from a dictionary. Python provides several approaches to accomplish this task efficiently. Below are two common methods using different programming constructs. Using Dictionary Comprehension Dictionary comprehension provides a clean and readable way to filter negative values. We iterate through each key-value pair and include only those with non-negative values ≥ Example dict_1 = {'x': 10, 'y': 20, 'z': -30, 'p': -0.5, 'q': 50} print("Given Dictionary:", dict_1) filtered_dict = {key: value for key, value in dict_1.items() if ...
Read MorePython - Filter even values from a list
As part of data analysis, we often need to filter values from a list meeting certain criteria. In this article, we'll see how to filter out only the even values from a list. To identify even numbers, we check if a number is divisible by 2 (remainder is zero when divided by 2). Python provides several approaches to filter even values from a list. Using for Loop This is the simplest way to iterate through each element and check for divisibility by 2 ? numbers = [33, 35, 36, 39, 40, 42] even_numbers = ...
Read MoreAll possible permutations of N lists in Python
When we have multiple lists and need to combine each element from one list with each element from another list, we're creating what's called a Cartesian product (not permutations). Python provides several approaches to achieve this combination. Using List Comprehension This straightforward approach uses nested list comprehension to create all possible combinations. The outer loop iterates through the first list, while the inner loop iterates through the second list ? Example A = [5, 8] B = [10, 15, 20] print("The given lists:", A, B) combinations = [[m, n] for m in A for ...
Read MorePython - Column summation of tuples
Python has extensive availability of various libraries and functions which make it so popular for data analysis. We may get a need to sum the values in a single column for a group of tuples for our analysis. So in this program we are adding all the values present at the same position or same column in a series of tuples. Column summation involves adding corresponding elements from tuples at the same positions. For example, if we have tuples (3, 92) and (25, 62), the column summation would be (28, 154). Using List Comprehension and zip() Using ...
Read Moremax() and min() in Python
Finding maximum and minimum values from a given list of values is a very common need in data processing programs. Python provides built-in max() and min() functions that handle both numbers and strings efficiently. Syntax max(iterable, *[, key, default]) min(iterable, *[, key, default]) Using max() and min() with Numeric Values Both functions work with integers, floats, and mixed numeric types to find the maximum and minimum values ? numbers = [10, 15, 25.5, 3, 2, 9/5, 40, 70] print("Maximum number is:", max(numbers)) print("Minimum number is:", min(numbers)) Maximum number is: ...
Read MoreGetter and Setter in Python
In Python, getters and setters are methods used to control access to an object's attributes. They provide a way to implement data encapsulation, ensuring that attributes are accessed and modified in a controlled manner. Getters retrieve the value of an attribute, while setters allow you to modify it. This approach helps prevent direct manipulation of attributes from outside the class. Basic Class with Public Attributes Let's start with a simple class that has a public attribute − class YearGraduated: def __init__(self, year=0): self.year ...
Read More