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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Display all the dates for a particular month using NumPy
NumPy is a powerful library in Python for scientific computing, particularly for dealing with arrays and matrices. One of the lesser-known features of NumPy is its ability to generate arrays of dates. In this article, we will explore how to use NumPy to display all the dates for a particular month. Using numpy.arange() with datetime64 To generate all dates for a particular month, we can use np.arange() with datetime64 objects. Let's create a complete example for April 2023 ─ import numpy as np # Define the month and year month = 4 # April ...
Read MoreArticle on Dispatch Decorator in Python
In Python, the @dispatch decorator enables function overloading based on argument types. This powerful feature allows you to define multiple implementations of the same function that are automatically selected at runtime based on the types of arguments passed. Python provides two main approaches for dispatch: functools.singledispatch for single-argument dispatch and the multipledispatch library for multiple-argument dispatch. What is Function Dispatch? Function dispatch is a mechanism that selects the appropriate function implementation based on the types of arguments provided. Instead of writing separate function names for different types, you can use the same function name and let Python ...
Read MorePython program to input a comma separated string
When working with user input, you often need to process comma-separated strings containing text, numbers, or mixed data. Python provides several approaches to split these strings into individual components and convert them to appropriate data types. Using split() Function for Text Strings The split() method is the most common approach to separate comma-delimited text ? # Input comma-separated string user_input = "apple, banana, cherry, dates" print("Original string:", user_input) # Split by comma and remove extra spaces items = [item.strip() for item in user_input.split(", ")] print("Processed list:", items) # Print each item on separate line ...
Read MorePerforming Runs test of Randomness in Python
The Runs test of randomness is a non-parametric statistical test used to determine whether a sequence of data points is random or exhibits systematic patterns. This test analyzes "runs" − consecutive sequences of values that are either above or below a certain threshold − to assess the randomness of data. Understanding the Runs Test A run is defined as a consecutive sequence of values that are either above or below a specified threshold (typically the median). The Runs test examines whether the number of runs in a dataset significantly deviates from what would be expected in a truly ...
Read MorePython program to print all positive numbers in a range
When working with ranges that include both positive and negative numbers, you often need to extract only the positive values. Python provides several approaches to filter positive numbers from a range: list comprehension, removal of negatives, filtering with conditions, and using the filter() function. Method 1: Using List Comprehension Create a separate list containing only positive numbers from the range − low_num = -10 high_num = 15 numbers = list(range(low_num, high_num + 1)) print("Original range:", numbers) # Extract positive numbers using list comprehension positive_numbers = [num for num in numbers if num > 0] ...
Read MorePython program to print all negative numbers in a range
Sometimes you need to extract only the negative numbers from a range. Python provides several methods to filter negative numbers: using loops, list comprehension, and built-in functions like filter(). Method 1: Using a Loop to Separate Negative Numbers Create a separate list for negative numbers and append them using a loop ? low_num = -10 high_num = 15 main_numbers = list(range(low_num, high_num + 1)) negative_numbers = [] print("Original range:", main_numbers) # Separate negative numbers into a new list for num in main_numbers: if num < 0: ...
Read MorePython program to find number of likes and dislikes?
The ability to analyze likes and dislikes on social media platforms is essential for understanding user engagement and sentiment. As a Python programmer, you'll often need to count these interactions to gauge content performance and user preferences. In this article, we'll explore two practical methods for counting likes and dislikes in Python datasets using different approaches. Approaches To count likes and dislikes in Python, we can use two effective methods ? Using the Counter class from collections Using manual loop iteration Let's examine both approaches with complete examples. Using Counter from Collections ...
Read MoreHow to Make a Time Series Plot with Rolling Average in Python?
In this article, we will explore two methods for creating a Python time series plot with a rolling average. Both approaches use popular libraries like Matplotlib, Pandas, and Seaborn, which provide powerful capabilities for data manipulation and visualization. Following these methods will enable you to visualize time series data with a rolling average efficiently and understand its general behavior. Both methods involve similar sequential steps: loading the data, converting the date column to a DateTime object, calculating the rolling average, and generating the plot. The primary difference lies in the libraries used for plotting. Sample Data For ...
Read MorePython Program to find minimum number of rotations to obtain actual string?
Understanding how to effectively handle strings is a fundamental programming task that can considerably enhance the performance of our code. Finding the least amount of rotations necessary to produce the desired string from a rotated string is an intriguing challenge in string manipulation. Situations like text processing, cryptography, and data compression frequently involve this issue. Consider the scenario in which a string is rotated a certain amount to the right. Finding the fewest rotations necessary to transform the string back into its original form is the objective. We can learn more about the string's structure and get access to ...
Read MorePython program to find maximum uppercase run?
Finding the longest consecutive sequence of uppercase letters in a string is a common text processing task. This problem appears in data analysis, text validation, and pattern extraction scenarios. We'll explore two efficient approaches: the iterative method and regular expressions. Approaches To find the maximum uppercase run in Python, we can use two methods: Using the iterative method Using regular expressions Let's examine both approaches in detail. Method 1: Using Iterative Approach The iterative method scans the string character by character, tracking the current run of ...
Read More