Vani Nalliappan

Vani Nalliappan

122 Articles Published

Articles by Vani Nalliappan

Page 11 of 13

Write a program in Python to round all the elements in a given series

Vani Nalliappan
Vani Nalliappan
Updated on 25-Mar-2026 197 Views

Rounding elements in a Pandas Series is a common data preprocessing task. Python provides multiple approaches: using the built-in round() method, manual iteration, or NumPy functions. Sample Data Let's start with a Series containing decimal values ? import pandas as pd data = pd.Series([1.3, 2.6, 3.9, 4.8, 5.6]) print("Original Series:") print(data) Original Series: 0 1.3 1 2.6 2 3.9 3 4.8 4 5.6 dtype: float64 Using round() Method The most efficient approach is using ...

Read More

How to print the days in a given month using Python?

Vani Nalliappan
Vani Nalliappan
Updated on 25-Mar-2026 427 Views

To print the days in a given month using Python, we can use Pandas to work with date series and extract the number of days using the dt.daysinmonth attribute. This is particularly useful when working with date datasets and you need to know how many days are in specific months. Solution To solve this, we will follow the steps given below ? Import pandas library Create a date range using pd.date_range() Convert to pandas Series Use Series.dt.daysinmonth to find the number of days Example Let us see the complete implementation to get a ...

Read More

Write a program in Python to print the day of the year in a given date series

Vani Nalliappan
Vani Nalliappan
Updated on 25-Mar-2026 388 Views

When working with date data in Pandas, you can extract the day of the year (1-366) from a date series using the dt.dayofyear accessor. This is useful for analyzing seasonal patterns or calculating time differences. Creating a Date Series First, let's create a date series using pd.date_range() to generate consecutive dates ? import pandas as pd # Create a date range starting from 2020-01-10 with 5 periods date_range = pd.date_range('2020-01-10', periods=5) date_series = pd.Series(date_range) print("Date Series:") print(date_series) Date Series: 0 2020-01-10 1 2020-01-11 2 2020-01-12 3 ...

Read More

Write a Python code to concatenate two Pandas series into a single series without repeating the index

Vani Nalliappan
Vani Nalliappan
Updated on 25-Mar-2026 428 Views

When working with Pandas Series, you often need to combine two series into one. By default, concatenating series preserves original indices, which can create duplicates. Using ignore_index=True creates a new sequential index starting from 0. Syntax pd.concat([series1, series2], ignore_index=True) Creating Two Series Let's start by creating two sample series with sequential data ? import pandas as pd series_one = pd.Series([1, 2, 3]) series_two = pd.Series([4, 5, 6]) print("Series One:") print(series_one) print("Series Two:") print(series_two) Series One: 0 1 1 2 2 ...

Read More

Write a Python code to create a series with your range values, generate a new row as sum of all the values and then convert the series into json file

Vani Nalliappan
Vani Nalliappan
Updated on 25-Mar-2026 561 Views

To create a Pandas series with range values, add a sum row, and convert to JSON format, we need to follow a structured approach using pandas library functions. Solution To solve this, we will follow the steps given below − Define a series with a range of 1 to 10 Find the sum of all the values Convert the series into JSON file format Let us see the following implementation to get a better understanding ? Example import pandas as pd ...

Read More

Write a program in Python to find the missing element in a given series and store the full elements in the same series

Vani Nalliappan
Vani Nalliappan
Updated on 25-Mar-2026 280 Views

Finding missing elements in a numerical series is a common data processing task. We can identify gaps in a sequence and fill them to create a complete series using Pandas and Python's range() function. Solution Approach To find and fill missing elements in a series, we follow these steps ? Create a Pandas Series with the original data Generate a complete range from the first to last element Check each number in the range and add it to a new list Convert the complete list back to a Pandas Series Example Let's find ...

Read More

Write a program in Python to generate any random five prime numbers between 100 to 150 in a Series

Vani Nalliappan
Vani Nalliappan
Updated on 25-Mar-2026 931 Views

To generate five random prime numbers between 100 and 150 using a Pandas Series, we need to first identify all prime numbers in this range, then randomly select five of them. Solution We will follow these steps − Create a function to check if a number is prime Find all prime numbers between 100 and 150 Use random.sample() to select 5 random primes Convert the result to a Pandas Series Example Let us see the implementation to generate random prime numbers − import pandas as pd import random def is_prime(num): ...

Read More

Write a program in Python to find the index for NaN value in a given series

Vani Nalliappan
Vani Nalliappan
Updated on 25-Mar-2026 983 Views

When working with data analysis in Python, you often encounter NaN (Not a Number) values in your datasets. Finding the indices where these NaN values occur is a common task. This guide shows multiple approaches to locate NaN indices in a Pandas Series. Creating a Sample Series Let's first create a sample series containing NaN values ? import pandas as pd import numpy as np l = [1, 2, 3, np.nan, 4, np.nan] data = pd.Series(l) print(data) 0 1.0 1 2.0 2 3.0 ...

Read More

Write a program in Python to filter the elements in a series which contains a string start and endswith 'a'

Vani Nalliappan
Vani Nalliappan
Updated on 25-Mar-2026 121 Views

In this tutorial, we'll learn how to filter elements in a Pandas Series that start and end with the same character. We'll explore different approaches to find strings that begin and end with 'a'. Sample Input and Output Input − Assume, you have a Series: 0 apple 1 oranges 2 alpha 3 aroma 4 beta Output − The result for elements that start and end with 'a': 2 alpha 3 aroma ...

Read More

Write a program in Python to print the power of all the elements in a given series

Vani Nalliappan
Vani Nalliappan
Updated on 25-Mar-2026 281 Views

Computing the power of each element in a Pandas Series means raising each element to itself (xx). This tutorial demonstrates three different approaches to achieve this operation. Input − Assume, you have a series, 0 1 1 2 2 3 3 4 Output − And, the result for the power of all elements in a series is, 0 1 1 4 2 27 3 ...

Read More
Showing 101–110 of 122 articles
« Prev 1 9 10 11 12 13 Next »
Advertisements