Asif Rahaman

Asif Rahaman

52 Articles Published

Articles by Asif Rahaman

52 articles

How to Use cbind in Python?

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 887 Views

Python doesn't have a built-in cbind function like R, but you can achieve column binding (combining columns from different data structures) using various methods. The term "cbind" stands for column bind, which means combining arrays or data structures side-by-side column-wise. Using zip() with List Comprehension The zip() function combines elements from multiple iterables, while list comprehension creates a new list by processing the zipped elements ? Syntax zip(iterable1, iterable2, ...) Example column1 = [1, 2, 3] column2 = [4, 5, 6] column3 = [7, 8, 9] combined = [list(t) for ...

Read More

How to Use axis=0 and axis=1 in Pandas?

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 8K+ Views

In Pandas, the axis parameter controls the direction of operations on DataFrames and Series. Understanding axis=0 and axis=1 is essential for performing row-wise and column-wise operations efficiently. Understanding Axis in Pandas A Pandas DataFrame is a two-dimensional table with rows and columns. The axis parameter determines how operations are applied: Axis 0 (rows) − Operations are applied along rows, working down vertically. Results are computed across rows for each column. Axis 1 (columns) − Operations are applied along columns, working across horizontally. Results are computed across columns for each row. ...

Read More

How to use a List as a dictionary key in Python 3?

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 322 Views

Dictionaries are among the most powerful data structures in Python. They consist of key-value pairs and offer O(1) time complexity for accessing values. However, you cannot directly use lists as dictionary keys because lists are mutable and therefore not hashable. Why Lists Cannot Be Dictionary Keys Lists are mutable data types in Python, meaning their contents can be modified after creation. Dictionary keys must be hashable (immutable) because Python uses hash values to efficiently store and retrieve key-value pairs. If a list's contents change after being used as a key, its hash value would change, making it impossible ...

Read More

How to Get the next key in Dictionary in Python?

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 2K+ Views

Dictionaries are powerful data types in Python that consist of key-value pairs. While accessing values in a dictionary is straightforward, there may be situations where you need to find the next key in a dictionary. Since Python dictionaries maintain insertion order (Python 3.7+), we can explore different methods to get the next key in a dictionary. Using keys() and index() Method The most straightforward approach is to convert dictionary keys into a list and use indexing to find the next key. Syntax dictionary_name.keys() list_object.index(key_name, start, end) The keys() method returns a view object ...

Read More

How to Get a sorted list of random integers with unique elements using Python?

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 478 Views

Generating random numbers is one of the most popular techniques in programming, statistics, machine learning models, etc. Creating a sorted list of random integers with unique elements is a common task. In this article, we will explore different approaches to get a sorted list of random integers with unique elements using Python. Using sample() Function from Random Module The random.sample() method generates random samples of k elements from a given population without replacement, ensuring unique elements. Syntax random.sample(population, k) sorted(iterable, key=None, reverse=False) The sample() function takes a population (iterable) and returns k unique ...

Read More

How to generate k random dates between two other dates using Python?

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 3K+ Views

Generating random dates is essential in data science applications like neural network training, stock market analysis, and statistical modeling. Python provides several approaches to generate k random dates between two specified dates using different libraries and techniques. Using random and datetime Modules The datetime module handles date operations while random generates random numbers. Combining these modules allows us to create random dates within a specified range. Example The following function generates k random dates by adding random days to the start date within the valid range ? import random from datetime import timedelta, datetime ...

Read More

Get the Most recent previous business day using Python

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 2K+ Views

In business applications, developers often need to calculate the most recent business day (excluding weekends). This is crucial for financial systems, reporting tools, and data analysis where operations only occur on weekdays. Using the datetime Library The datetime library provides built-in classes to handle dates and times. We can use timedelta to subtract days and check if the result is a business day using the weekday() method. Syntax timedelta(days=) The timedelta class represents the difference between two dates. The days parameter specifies how many days to add or subtract. Example This ...

Read More

Gaussian fit using Python

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 7K+ Views

Data analysis and visualization are crucial nowadays, where data is the new oil. Typically data analysis involves feeding the data into mathematical models and extracting useful information. The Gaussian fit is a powerful mathematical model that data scientists use to model data based on a bell-shaped curve. In this article, we will understand Gaussian fit and how to implement it using Python. What is Gaussian Fit A bell-shaped curve characterizes the Gaussian distribution. The bell-shaped curve is symmetrical around the mean (μ). We define a probability density function as follows: f(x) = (1 / (σ * ...

Read More

Python - Leaf and Non-Leaf Nodes Dictionary

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 610 Views

Dictionary is an important data structure in Python which consists of key-value pairs. A nested dictionary can represent tree-like structures with nodes, where some nodes are leaf nodes (terminal nodes with no children) and others are non-leaf nodes (internal nodes with children). In this article, we will explore different approaches to identify and manipulate leaf and non-leaf nodes in Python dictionaries. What are Leaf and Non-Leaf Nodes? In tree-like dictionary structures, nodes are categorized based on whether they have children ? Leaf node: A node that does not have any child nodes. These are terminal nodes ...

Read More

Python - Lambda function to find the smaller value between two elements

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 517 Views

Lambda functions are anonymous functions in Python that provide a concise way to write small operations without defining a full function. In this article, we'll explore different methods to find the smaller value between two elements using lambda functions. Using Conditional Expression (if-else) The most straightforward approach uses Python's conditional expression within a lambda function ? # Direct lambda with conditional expression smaller = lambda a, b: a if a < b else b a = 45 b = 24 result = smaller(a, b) print(f"The smaller number between {a} and {b} is: {result}") ...

Read More
Showing 1–10 of 52 articles
« Prev 1 2 3 4 5 6 Next »
Advertisements