Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 20 of 377

Python Pandas - Return proleptic Gregorian ordinal

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 311 Views

To return proleptic Gregorian ordinal, use the timestamp.toordinal() method. The proleptic Gregorian ordinal is the number of days since January 1 of year 1, where January 1 of year 1 is day 1. Understanding Proleptic Gregorian Ordinal The proleptic Gregorian calendar extends the Gregorian calendar backward to dates before its introduction in 1582. The ordinal represents the total number of days elapsed since the theoretical date January 1, 1 AD. Basic Usage First, import the required library and create a timestamp object ? import pandas as pd # Create the timestamp object timestamp ...

Read More

Python Pandas - Get the current date and time from Timestamp object

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 9K+ Views

To get the current date and time from a Pandas Timestamp object, use the timestamp.today() method. This method returns the current system date and time, regardless of the original timestamp value. Import Required Libraries First, import the necessary libraries ? import pandas as pd import datetime Creating a Timestamp Object Create a Pandas Timestamp object with a specific date ? # Create a timestamp with a specific date timestamp = pd.Timestamp(datetime.datetime(2021, 10, 10)) print("Original Timestamp:", timestamp) print("Day Name from Timestamp:", timestamp.day_name()) Original Timestamp: 2021-10-10 00:00:00 Day Name from ...

Read More

Python Pandas - Convert given Timestamp to Period

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 883 Views

To convert a given Timestamp to Period in Pandas, use the timestamp.to_period() method. The freq parameter sets the frequency for the period conversion. Syntax timestamp.to_period(freq=None) Parameters freq − Frequency string (e.g., 'D' for daily, 'M' for monthly, 'Y' for yearly) Basic Example Here's how to convert a timestamp to a monthly period − import pandas as pd # Create a timestamp object timestamp = pd.Timestamp('2021-09-14T15:12:34.261811624') # Display the original timestamp print("Original Timestamp:") print(timestamp) # Convert timestamp to monthly period monthly_period = timestamp.to_period(freq='M') print("Converted to Monthly Period:") print(monthly_period) ...

Read More

Program to count indices pairs for which elements sum is power of 2 in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 389 Views

Given a list of numbers, we need to find the number of index pairs (i, j) where i < j such that nums[i] + nums[j] equals a power of 2 (2^k for some k ≥ 0). Problem Understanding For the input nums = [1, 2, 6, 3, 5], we have three valid pairs: (6, 2): sum is 8 = 2^3 (5, 3): sum is 8 = 2^3 (1, 3): sum is 4 = 2^2 Algorithm Approach We use a frequency counter to track elements we've seen. For each element x, we check if ...

Read More

Program to check we can get a digit pair and any number of digit triplets or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 327 Views

Suppose we have a numeric string s. We have to check whether there is some arrangement where we can have one pair of the same character and the rest of the string form any number of triplets of the same characters. So, if the input is like s = "21133123", then the output will be True, because there are two 2s to form "22" as the pair and "111", "333" as two triplets. Algorithm To solve this, we will follow these steps ? d := a list containing frequencies of each elements ...

Read More

Program to check string is palindrome with lowercase characters or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 910 Views

Suppose we have an alphanumeric string s that can hold both uppercase and lowercase letters. We need to check whether s is a palindrome considering only the lowercase alphabet characters. So, if the input is like s = "rLacHEec0a2r8", then the output will be True because the string contains "racecar" in lowercase, which is a palindrome. Algorithm To solve this, we will follow these steps − Extract all lowercase characters from the string Check if the extracted string equals its reverse Return True if palindrome, False otherwise Example Let us see the ...

Read More

Program to find mutual followers from a relations list in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 271 Views

Suppose we have a list called relations, where each element relations[i] contains two numbers [ai, bi] indicating that person ai is following bi on a social media platform. We need to find mutual followers − people who follow someone and are followed back by them. The result should be returned in sorted order. So, if the input is like relations = [[0, 2], [2, 3], [2, 0], [1, 0]], then the output will be [0, 2] because person 0 follows person 2, and person 2 follows person 0 back. Algorithm To solve this, we will follow these ...

Read More

Program to find minimum number of monotonous string groups in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 439 Views

Suppose we have a lowercase string s. We need to find the minimum number of contiguous substrings that s can be divided into, where each substring is either non-increasing (monotonically decreasing) or non-decreasing (monotonically increasing). For example, "pqqqr" is a non-decreasing string, and "qqqp" is a non-increasing string. Problem Example If the input is s = "pqrsrqp", then the output will be 2, because we can break s into "pqrs" (non-decreasing) and "rqp" (non-increasing). Algorithm Steps To solve this problem, we follow these steps ? If string is empty, ...

Read More

Program to find minimum value to insert at beginning for all positive prefix sums in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 279 Views

Suppose we have a list of numbers called nums. We have to find the minimum positive value that we can insert at the beginning of nums so that the prefix sums of the resulting list are all positive (greater than 0). So, if the input is like nums = [3, -6, 4, 3], then the output will be 4, because if we insert 4 to the list then we have [4, 3, -6, 4, 3]. Now the prefix sums are [4, 7, 1, 5, 8], all are positive. Algorithm To solve this, we will follow these steps ...

Read More

Program to find minimum distance of two given words in a text in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 2K+ Views

Finding the minimum distance between two words in a text is a common string processing problem. The distance is measured as the number of words between any occurrence of the two target words. Given a text string and two words w1 and w2, we need to find the smallest number of words between any occurrences of these words. If either word is not present, we return -1. Algorithm The approach involves tracking the most recent positions of both words as we iterate through the text ? Initialize index1 and index2 as None Set distance to ...

Read More
Showing 191–200 of 3,768 articles
« Prev 1 18 19 20 21 22 377 Next »
Advertisements