Programming Articles

Page 95 of 2547

Plot Line Graph from NumPy Array

Shriansh Kumar
Shriansh Kumar
Updated on 27-Mar-2026 4K+ Views

A line graph is a common way to display the relationship between two dependent datasets. Its general purpose is to show change over time. To plot a line graph from the NumPy array, we can use matplotlib which is the oldest and most widely used Python library for plotting. Also, it can be easily integrated with NumPy which makes it easy to create line graphs to represent trends and patterns in the given datasets. Basic Line Graph from NumPy Array Here's how to create a simple line graph using NumPy arrays and matplotlib ? import numpy ...

Read More

Percentile Rank of a Column in a Pandas DataFrame

Shriansh Kumar
Shriansh Kumar
Updated on 27-Mar-2026 3K+ Views

The percentile rank shows what percentage of values in a dataset are less than or equal to a given value. In pandas, we can calculate percentile ranks using the rank() method or scipy's percentileofscore() function. What is Percentile Rank? If a student scores in the 80th percentile, it means their score is greater than or equal to 80% of all other scores in the dataset. Using rank() Method The most common approach is using pandas' rank() method with pct=True parameter ? import pandas as pd # Create sample DataFrame data = {'Name': ['Ram', ...

Read More

Highlight Pandas DataFrame\'s Specific Columns using Apply()

Shriansh Kumar
Shriansh Kumar
Updated on 27-Mar-2026 2K+ Views

While presenting or explaining data using Pandas DataFrames, we might need to highlight important rows and columns to make them more appealing, explainable and visually stunning. One way of highlighting specific columns is by using the built-in apply() method with Pandas styling. Understanding apply() with Pandas Styling The apply() method is used to apply a user-defined function to each column or row of the Pandas DataFrame. To highlight specific columns, we first define a custom function that sets the required conditions for highlighting, then use the apply() method along with the style module. Syntax df.style.apply(function_name) ...

Read More

Hierarchical Data in Pandas

Shriansh Kumar
Shriansh Kumar
Updated on 27-Mar-2026 3K+ Views

Hierarchical data represents multiple levels of nested groups or categories, such as company departments with employees, or products with categories and subcategories. Pandas provides powerful tools like MultiIndex, set_index(), and groupby() to effectively represent and analyze hierarchical data structures. Understanding MultiIndex in Pandas A MultiIndex creates a hierarchical index structure with multiple levels, allowing you to organize data in a tree-like format within a DataFrame. Creating Hierarchical Data with set_index() The set_index() method converts regular columns into a hierarchical index ? import pandas as pd # Creating sample hierarchical data data = { ...

Read More

Plot a Vertical line in Matplotlib

Shriansh Kumar
Shriansh Kumar
Updated on 27-Mar-2026 9K+ Views

Python's Matplotlib library provides powerful tools for creating visual representations in the form of plots and graphs. One useful feature is plotting vertical lines to add reference lines or highlight specific points on plots. The built-in methods axvline(), vlines(), and plot() allow you to create vertical lines with customizable parameters such as position, color, and linestyle. Using axvline() Method The axvline() method is the simplest way to plot a vertical line in Matplotlib. It automatically spans the entire y-axis of the plot, making it ideal for reference lines. Syntax axvline(x=position, color='color', linestyle='style', alpha=transparency) ...

Read More

How to Convert Categorical Features to Numerical Features in Python?

Prince Yadav
Prince Yadav
Updated on 27-Mar-2026 634 Views

In machine learning, data comes in different types, including numerical, categorical, and text data. Categorical features are features that take on a limited set of values, such as colors, genders, or countries. However, most machine learning algorithms require numerical features as inputs, which means we need to convert categorical features to numerical features before training our models. In this article, we will explore various techniques to convert categorical features to numerical features in Python. We will discuss label encoding, one-hot encoding, binary encoding, count encoding, and target encoding, with complete working examples. Label Encoding Label encoding converts ...

Read More

How to Convert Bytes to Int in Python?

Prince Yadav
Prince Yadav
Updated on 27-Mar-2026 32K+ Views

In this tutorial, we will explore different methods to convert bytes to integers in Python. Converting bytes to integers is a common task when dealing with binary data, such as reading data from files or network sockets. By converting bytes to integers, we can perform various arithmetic and logical operations, interpret data, and manipulate it as needed. Using int.from_bytes() Method The int.from_bytes() method is the standard way to create an integer from a sequence of bytes. It takes two main parameters: the bytes to convert and the byte order ('big' or 'little'). Basic Conversion Let's convert ...

Read More

Appending to list in Python Dictionary

Shriansh Kumar
Shriansh Kumar
Updated on 27-Mar-2026 2K+ Views

Sometimes, we may need to store a list as the value of a dictionary key and later update or add more elements to that list. Python provides several ways for appending elements to a list in a Python dictionary. In this article, we'll explore the append() method, += operator, and update() method for this purpose. Understanding Lists and Dictionaries Before diving into the methods, let's understand the basic data structures we're working with. List A list is an ordered and mutable collection of elements. We create lists by placing elements in square brackets separated by commas ...

Read More

How to Convert an Image to a NumPy Array and Save it to a CSV file using Python?

Prince Yadav
Prince Yadav
Updated on 27-Mar-2026 980 Views

Python is a powerful programming language with a vast array of libraries and modules. One such library is NumPy, which is used for numerical computing and processing large multidimensional arrays and matrices. Another popular library used for image processing in Python is Pillow, which is a fork of the Python Imaging Library (PIL). In this tutorial, we will show you how to convert an image to a NumPy array and save it to a CSV file using Python. We will be using the Pillow library to open the image and convert it to a NumPy array, and NumPy's built-in ...

Read More

How to convert a nested OrderedDict to Dict in Python?

Prince Yadav
Prince Yadav
Updated on 27-Mar-2026 1K+ Views

Python's OrderedDict is a dictionary subclass that remembers insertion order. When working with nested data structures, you may need to convert a nested OrderedDict to a regular dict for easier processing or compatibility with other functions. What is an OrderedDict? An OrderedDict is a subclass of a regular dictionary that maintains the order of items as they were inserted. A nested OrderedDict contains other OrderedDict objects as values, creating hierarchical data structures. Here's an example of a nested OrderedDict ? from collections import OrderedDict nested_odict = OrderedDict({ 'Name': 'John Doe', ...

Read More
Showing 941–950 of 25,466 articles
« Prev 1 93 94 95 96 97 2547 Next »
Advertisements