Vani Nalliappan

Vani Nalliappan

122 Articles Published

Articles by Vani Nalliappan

Page 6 of 13

Write a program in Python to caluculate the adjusted and non-adjusted EWM in a given dataframe

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

The Exponentially Weighted Moving Average (EWM) is a statistical technique that gives more weight to recent observations. Pandas provides two modes: adjusted (default) and non-adjusted, which handle the calculation differently during the initial periods. Understanding EWM Parameters The key difference between adjusted and non-adjusted EWM lies in how they handle the bias correction ? Adjusted EWM (default): Applies bias correction to account for the initialization period Non-adjusted EWM: Uses raw exponential weighting without bias correction com parameter: Center of mass, controls the decay rate (higher values = slower decay) Creating Sample Data First, ...

Read More

Write a Python code to fill all the missing values in a given dataframe

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

When working with datasets, missing values (NaN) are common. Pandas provides the interpolate() method to fill missing values using various interpolation techniques like linear, polynomial, or time-based methods. Syntax df.interpolate(method='linear', limit_direction='forward', limit=None) Parameters method − Interpolation technique ('linear', 'polynomial', 'spline', etc.) limit_direction − Direction to fill ('forward', 'backward', 'both') limit − Maximum number of consecutive NaNs to fill Example Let's create a DataFrame with missing values and apply linear interpolation ? import pandas as pd df = pd.DataFrame({"Id": [1, 2, 3, None, 5], ...

Read More

Write a Python code to rename the given axis in a dataframe

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

In Pandas, you can rename the axis (row index or column names) of a DataFrame using the rename_axis() method. This is useful when you want to give a meaningful name to your DataFrame's index or columns axis. Syntax DataFrame.rename_axis(mapper, axis=None, copy=None, inplace=False) Parameters mapper − The new name for the axis axis − 0 or 'index' for row axis, 1 or 'columns' for column axis inplace − If True, modify the DataFrame in place Renaming the Column Axis Let's create a DataFrame and rename its column axis ? ...

Read More

Write a Python code to find a cross tabulation of two dataframes

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

Cross-tabulation (crosstab) creates a frequency table showing relationships between categorical variables from different DataFrames. Pandas provides the pd.crosstab() function to compute cross-tabulations between two or more factors. Creating Sample DataFrames Let's start by creating two DataFrames with related data ? import pandas as pd # First DataFrame with Id and Age df = pd.DataFrame({'Id': [1, 2, 3, 4, 5], 'Age': [12, 13, 12, 13, 14]}) print("DataFrame 1:") print(df) # Second DataFrame with Mark df1 = pd.DataFrame({'Mark': [80, 90, 80, 90, 85]}) print("DataFrame 2:") print(df1) DataFrame 1: Id ...

Read More

Write a program in Python to print the length of elements in all column in a dataframe using applymap

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

The applymap() function in Pandas allows you to apply a function element-wise to every cell in a DataFrame. This is useful when you want to calculate the length of string elements across all columns. Understanding applymap() The applymap() method applies a function to each element of the DataFrame. Unlike apply(), which works on rows or columns, applymap() works on individual elements. Syntax DataFrame.applymap(func) Where func is the function to apply to each element. Example Let's create a DataFrame and calculate the length of elements in all columns ? import ...

Read More

Write a Python code to calculate percentage change between Id and Age columns of the top 2 and bottom 2 values

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

Sometimes we need to calculate percentage changes between consecutive rows in specific columns of a DataFrame. The pct_change() method calculates the percentage change from the previous row, which is useful for analyzing trends in data. Understanding Percentage Change The pct_change() method computes the percentage change between the current and previous element. The formula is: (current - previous) / previous. Example Dataset Let's start by creating a sample DataFrame with Id and Age columns ? import pandas as pd df = pd.DataFrame({ "Id": [1, 2, 3, None, 5], ...

Read More

Write a Python program to perform table-wise pipe function in a dataframe

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

The pipe() function in Pandas allows you to apply a custom function to an entire DataFrame. This is useful for performing table-wise operations where you want to transform the entire dataset using a user-defined function. Understanding DataFrame pipe() Function The pipe() method passes the DataFrame as the first argument to a function, along with any additional arguments you specify. This enables method chaining and cleaner code organization. Syntax DataFrame.pipe(func, *args, **kwargs) Example: Table-wise Operation Let's create a DataFrame and apply a custom function using pipe() ? import pandas as pd ...

Read More

Write a Python program to trim the minimum and maximum threshold value in a dataframe

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

Sometimes you need to limit values in a DataFrame to fall within specific minimum and maximum thresholds. Pandas provides the clip() method to trim values that exceed these boundaries. Understanding DataFrame Clipping The clip() method constrains values between a lower and upper limit: lower parameter sets the minimum threshold upper parameter sets the maximum threshold Values below the lower limit are replaced with the lower limit Values above the upper limit are replaced with the upper limit Syntax DataFrame.clip(lower=None, upper=None, axis=None) Creating Sample Data Let's create a DataFrame with ...

Read More

Write a Python program to quantify the shape of a distribution in a dataframe

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

Distribution shape analysis is crucial in data science for understanding data characteristics. Python's Pandas provides built-in methods to calculate kurtosis (measures peakedness) and skewness (measures asymmetry) to quantify distribution shapes. What is Kurtosis and Skewness? Kurtosis measures how peaked or flat a distribution is compared to a normal distribution. Values above 0 indicate a more peaked distribution, while negative values indicate a flatter distribution. Skewness measures the asymmetry of a distribution. Positive skewness indicates a tail extending toward higher values, while negative skewness indicates a tail extending toward lower values. Creating a Sample DataFrame Let's ...

Read More

Write a Python program to find the mean absolute deviation of rows and columns in a dataframe

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

Mean Absolute Deviation (MAD) measures the average distance between each data point and the mean of the dataset. In pandas, you can calculate MAD for both rows and columns of a DataFrame using the mad() method. What is Mean Absolute Deviation? MAD is calculated as the mean of absolute deviations from the arithmetic mean: MAD = mean(|x - mean(x)|) Creating a Sample DataFrame Let's start by creating a DataFrame with sample data ? import pandas as pd data = {"Column1": [6, 5.3, 5.9, 7.8, 7.6, 7.45, 7.75], ...

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