Vani Nalliappan

Vani Nalliappan

122 Articles Published

Articles by Vani Nalliappan

Page 6 of 13

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

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

When working with Pandas Series, you might need to shuffle the elements to randomize their order. Python provides multiple approaches to shuffle a series: using random.shuffle() directly or implementing a manual shuffle algorithm. Using random.shuffle() The simplest approach is to use Python's built-in random.shuffle() method, which shuffles the series elements in-place ? import pandas as pd import random as rand data = pd.Series([1, 2, 3, 4, 5]) print("The original series is:") print(data) rand.shuffle(data) print("The shuffled series is:") print(data) The original series is: 0 1 1 ...

Read More

Write a program in Python to covert the datatype of a particular column in a dataframe

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

In Pandas, you can convert the datatype of a specific column using the astype() method. This is useful when you need to change data types for analysis, memory optimization, or data consistency. Creating a Sample DataFrame Let's start by creating a DataFrame with mixed data types ? import pandas as pd data = {'Name': ['David', 'Adam', 'Bob', 'Alex', 'Serina'], 'Age': [13, 12, 12, 13, 12], 'Maths': [98, 59, 66, 95, 70], ...

Read More

Write a Python code to swap last two rows in a given dataframe

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

In Pandas, you can swap the last two rows of a DataFrame using iloc indexing. This technique temporarily stores one row, assigns the other row's values, and then restores the stored row. Approach To swap the last two rows, we follow these steps ? Store the last row in a temporary variable using df.iloc[-1] Assign the second-to-last row values to the last row position Assign the temporary row data to the second-to-last position Example Let's create a DataFrame and swap its last two rows ? import pandas as pd data ...

Read More

Write a program in Python to remove one or more than one columns in a given DataFrame

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

Sometimes you need to remove one or more columns from a Pandas DataFrame. Python provides several methods to accomplish this: using del statement, pop() method, and drop() method. Using del Statement The del statement permanently removes a single column from the DataFrame ? import pandas as pd data = [[1, 2, 3], [4, 5, 6]] df = pd.DataFrame(data, columns=('one', 'two', 'three')) print("Before deletion:") print(df) del df['one'] print("After deletion:") print(df) Before deletion: one two three 0 1 2 ...

Read More

Write a program in Python to find the most repeated element in a series

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

Finding the most repeated element in a pandas Series is a common data analysis task. We'll explore different approaches to solve this problem efficiently. Sample Series Let's start with a sample Series to demonstrate the concept ? import pandas as pd data_list = [1, 22, 3, 4, 22, 5, 22] series = pd.Series(data_list) print("Series is:") print(series) Series is: 0 1 1 22 2 3 3 4 4 22 5 5 ...

Read More

Write a program in Python to select any random odd index rows in a given DataFrame

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

In data analysis, you often need to randomly select rows from a DataFrame based on certain criteria. This tutorial shows how to select a random row from odd-indexed positions (1, 3, 5, etc.) in a Pandas DataFrame. Sample DataFrame Let's start with a sample DataFrame to demonstrate the concept ? import pandas as pd import random df = pd.DataFrame({ 'id': [1, 2, 3, 4, 5, 6, 7], 'mark': [70, 60, 40, 50, 80, 90, 60], 'age': [12, 13, 12, 13, 12, 13, 12] ...

Read More

Write a program in Python to merge two dataframes based on matching data in a column

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

In data analysis, you often need to combine data from multiple DataFrames based on common columns. Pandas provides the merge() function to join DataFrames similar to SQL joins. Understanding DataFrame Merging When you have two DataFrames with a common column, you can merge them to create a single DataFrame containing matching records. The merge operation finds rows where the specified column values match between both DataFrames. Creating Sample DataFrames Let's start by creating two DataFrames with a common 'id' column ? import pandas as pd # First DataFrame first_df = pd.DataFrame({ ...

Read More

Write a Python program to generate random ten rows, two columns of vowels. If both the rows are matched with same vowels, then print the index and count of matched columns

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

In this tutorial, we'll create a Python program that generates a DataFrame with ten rows and two columns of random vowels, then finds rows where both columns have matching vowels and counts them. Problem Overview We need to ? Generate a DataFrame with 10 rows and 2 columns containing random vowels Find rows where both columns have the same vowel Display the matched rows and count them Sample DataFrame Here's an example of what our DataFrame might look like ? col1 col2 0 o ...

Read More

Write a program in Python to modify the diagonal of a given DataFrame by 1

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

In data analysis, we often need to modify specific elements of a DataFrame. One common task is modifying the diagonal elements − where the row index equals the column index (positions [0, 0], [1, 1], [2, 2], etc.). Understanding the Diagonal The diagonal of a square DataFrame consists of elements where row index equals column index. For a 3x3 DataFrame, the diagonal elements are at positions (0, 0), (1, 1), and (2, 2). ...

Read More

Write a program in Python to find the lowest value in a given DataFrame and store the lowest value in a new row and column

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

In this tutorial, we'll learn how to find the minimum values in a Pandas DataFrame and store them in both a new column and a new row. This is useful for data analysis when you need to track minimum values across rows and columns. Creating the Sample DataFrame Let's start by creating a sample DataFrame to work with ? import pandas as pd data = [[12, 13, 5], [10, 6, 4], [16, 18, 20], [11, 15, 58]] df = pd.DataFrame(data, columns=['one', 'two', 'three']) print("Original DataFrame:") print(df) Original DataFrame: one ...

Read More
Showing 51–60 of 122 articles
« Prev 1 4 5 6 7 8 13 Next »
Advertisements