Server Side Programming Articles

Page 93 of 2109

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 630 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 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

How to Convert a List to a DataFrame Row in Python?

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

Python's pandas library provides powerful tools for data manipulation. Converting a list to a DataFrame row is a common task when you need to add new data to existing datasets. This tutorial shows you how to convert a list into a DataFrame row using pandas. Method 1: Using pd.DataFrame() Constructor The most straightforward approach is to create a DataFrame directly from a list with specified column names: import pandas as pd # Create a list of data new_row_data = ['Prince', 26, 'New Delhi'] # Convert list to DataFrame row df = pd.DataFrame([new_row_data], columns=['Name', 'Age', ...

Read More

All Combinations For A List Of Objects

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

Generating all combinations for a list of objects is a common operation in Python. The itertools module provides efficient built-in methods like combinations() and product() to generate different types of combinations from list objects. Using itertools.combinations() The combinations() method generates all possible combinations of a specified length without repetition. It's perfect for mathematical combinations where order doesn't matter and elements can't repeat. Syntax itertools.combinations(iterable, length) Where iterable is the input sequence and length is the size of each combination. Example 1: Basic Combinations Generate all combinations of different lengths from a ...

Read More

How to Control Laptop Screen Brightness Using Python?

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

Python can be used to control various system functions, including laptop screen brightness. The screen-brightness-control library provides simple functions to get and set screen brightness levels programmatically. In this tutorial, we'll explore how to install and use the screen-brightness-control library to control laptop screen brightness using Python code. Installing the Screen Brightness Control Library First, we need to install the screen-brightness-control library using pip ? pip install screen-brightness-control This command will download and install the latest version of the library along with any required dependencies. Getting Current Screen Brightness Let's start ...

Read More

How to Connect Scatterplot Points With Line in Matplotlib?

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

Matplotlib allows you to create scatter plots and enhance them by connecting points with lines. This technique helps visualize trends and patterns in data more effectively. Basic Setup First, import the necessary libraries ? import matplotlib.pyplot as plt import numpy as np Method 1: Using plot() After scatter() Create a scatter plot first, then add a line connecting the points ? import matplotlib.pyplot as plt import numpy as np # Generate sample data x = np.array([1, 2, 3, 4, 5, 6]) y = np.array([2, 5, 3, 8, 7, 6]) ...

Read More
Showing 921–930 of 21,090 articles
« Prev 1 91 92 93 94 95 2109 Next »
Advertisements