Vani Nalliappan

Vani Nalliappan

122 Articles Published

Articles by Vani Nalliappan

Page 9 of 13

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

Write a program in Python to read sample data from an SQL Database

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

Reading data from SQL databases is a common task in data analysis. Python's pandas library provides the read_sql_query() function to easily fetch data from databases and convert it into a DataFrame. Prerequisites You need a SQLite database file with sample data. For this example, we assume you have a db.sqlite3 file containing a student table with the following structure ? Id Name 0 1 stud1 1 2 stud2 2 3 stud3 3 4 stud4 4 5 stud5 Steps to Read ...

Read More

Write a Pyton program to perform Boolean logical AND, OR, Ex-OR operations for a given series

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

Boolean logical operations on Pandas Series allow you to perform element-wise AND, OR, and XOR operations using bitwise operators &, |, and ^. These operations are useful for filtering data and creating conditional logic. Creating a Boolean Series First, let's create a Pandas Series with boolean values including np.nan ? import pandas as pd import numpy as np # Create a boolean series with True, NaN, and False series = pd.Series([True, np.nan, False], dtype="bool") print("Original series:") print(series) Original series: 0 True 1 True 2 ...

Read More

Write a program in Python to transpose the index and columns in a given DataFrame

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

Transposing a DataFrame means swapping its rows and columns. Python provides several methods to transpose DataFrames, from using Pandas built-in methods to implementing custom solutions with list comprehensions or zip operations. Using DataFrame.transpose() or .T The most straightforward approach is using Pandas' built-in transpose() method or its shorthand .T property ? import pandas as pd data = [[1, 2, 3], [4, 5, 6]] df = pd.DataFrame(data) print("Original DataFrame:") print(df) print("Transposed DataFrame:") print(df.transpose()) Original DataFrame: 0 1 2 0 1 2 3 1 ...

Read More

Write a program in Python to shift the first column and get the value from the user, if the input is divisible by both 3 and 5 and then fill the missing value

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

This article demonstrates how to shift DataFrame columns and conditionally fill missing values based on user input. We'll shift the first column to the right and fill the new empty column with a user-provided value only if it's divisible by both 3 and 5. Understanding Column Shifting The shift() method with axis=1 shifts columns horizontally. When shifting right, the first column becomes empty and needs to be filled. Creating the DataFrame import pandas as pd data = pd.DataFrame({ 'one': [1, 2, 3], 'two': [10, 20, 30], ...

Read More

Write a program in Python to calculate the default float quantile value for all the element in a Series

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

A quantile represents the value below which a certain percentage of data falls. In pandas, the quantile() method calculates quantile values for a Series, with 0.5 being the default (median). Understanding Quantiles The quantile value of 0.5 represents the median − the middle value when data is sorted. For a Series with values [10, 20, 30, 40, 50], the 0.5 quantile (median) is 30.0. Syntax Series.quantile(q=0.5, interpolation='linear') Parameters: q − Float between 0 and 1 (default is 0.5) interpolation − Method to use when quantile lies between two data points ...

Read More
Showing 81–90 of 122 articles
« Prev 1 7 8 9 10 11 13 Next »
Advertisements