Server Side Programming Articles

Page 127 of 2109

How to load and save 3D Numpy Array file using savetxt() and loadtxt() functions?

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 5K+ Views

When working with 3D NumPy arrays, savetxt() and loadtxt() functions cannot directly handle them since they expect 2D arrays. To save and load 3D arrays, you need to reshape them to 2D format first, then reshape back to 3D after loading. The Problem with 3D Arrays Using savetxt() or loadtxt() with 3D arrays directly throws an error: ValueError: Expected 1D or 2D array, got 3D array instead Solution: Reshape Before Saving and After Loading The solution involves three steps: Reshape 3D array to 2D before saving Save/load using savetxt()/loadtxt() Reshape back ...

Read More

How to lowercase the column names in Pandas dataframe?

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 6K+ Views

In this article, you'll learn how to convert column names and values to lowercase in a Pandas DataFrame. We'll explore three different methods: str.lower(), map(str.lower), and apply(lambda) functions. Creating a Sample DataFrame Let's start by creating a sample DataFrame to demonstrate the methods ? import pandas as pd # Create sample restaurant data data = { 'Restaurant Name': ['Pizza Palace', 'Burger King', 'Sushi Bar'], 'Rating Color': ['Green', 'Yellow', 'Red'], 'Rating Text': ['Excellent', 'Good', 'Average'] } df = pd.DataFrame(data) print("Original DataFrame:") print(df) ...

Read More

How to load a TSV file into a Pandas Dataframe?

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 5K+ Views

A TSV (Tab Separated Values) file is a text format where data columns are separated by tabs. Pandas provides two main methods to load TSV files into DataFrames: read_table() with delimiter='\t' and read_csv() with sep='\t'. Method 1: Using read_table() with delimiter='\t' The read_table() function is specifically designed for reading delimited text files ? import pandas as pd # Create a sample TSV data for demonstration tsv_data = """Name Age City Salary John 25 New York 50000 Alice 30 London 60000 Bob 28 Paris 55000 Carol 32 Tokyo 65000""" # Save sample data to a TSV file with open('sample.tsv', 'w') as f: f.write(tsv_data) # Load ...

Read More

How to create a seaborn correlation heatmap in Python?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 9K+ Views

A correlation heatmap is a graphical representation that displays the correlation matrix of a dataset using colors to show the strength and direction of relationships between variables. It's an effective tool for identifying patterns and connections in large datasets. Seaborn, a Python data visualization library, provides simple utilities for creating statistical visualizations including correlation heatmaps. The process involves importing your dataset, computing the correlation matrix, and using Seaborn's heatmap function to generate the visualization. Using the heatmap() Function The heatmap() function generates a color-coded matrix showing correlations between variable pairs. It requires a correlation matrix as input, ...

Read More

Find the size of a Dictionary in Python

Atharva Shah
Atharva Shah
Updated on 27-Mar-2026 7K+ Views

In Python, you often need to determine the size of a dictionary for memory allocation, performance optimization, or data validation. Python provides two main approaches: counting key-value pairs using len() and measuring memory usage with sys.getsizeof(). Syntax The syntax to determine a dictionary's size is straightforward ? # Count key-value pairs size = len(dictionary) # Get memory size in bytes import sys memory_size = sys.getsizeof(dictionary) Using len() Function The len() function returns the number of key-value pairs in the dictionary ? my_dict = {"apple": 2, "banana": 4, "orange": 3} size ...

Read More

Find the siblings of tags using BeautifulSoup

Atharva Shah
Atharva Shah
Updated on 27-Mar-2026 1K+ Views

Data may be extracted from websites using the useful method known as web scraping. A popular Python package for web scraping is BeautifulSoup, which offers a simple method for parsing HTML and XML documents. Finding the siblings of a tag is a frequent task while scraping web pages − siblings are any additional tags that have the same parent as the primary tag. Installation and Setup To use BeautifulSoup, you must first install it using pip ? pip install beautifulsoup4 Once installed, you can import BeautifulSoup in your Python code ? from ...

Read More

Find the profit and loss in the given Excel sheet using Pandas

Atharva Shah
Atharva Shah
Updated on 27-Mar-2026 680 Views

Pandas is a popular data manipulation and analysis library in Python that is widely used by data scientists and analysts. It provides several functions for working with data in Excel sheets. One of the most common tasks in analyzing financial data is finding the profit and loss in a given Excel sheet. Setup To handle Excel files in Python, you need to install the openpyxl dependency. To do this, open your terminal and type the command − pip install openpyxl After successful installation you can proceed with experimenting with Excel files and spreadsheets. ...

Read More

Find the position of number that is multiple of certain number

Atharva Shah
Atharva Shah
Updated on 27-Mar-2026 235 Views

When working with lists in Python, you often need to find the positions (indices) of numbers that are multiples of a specific number. Python provides several approaches to accomplish this task efficiently using loops, list comprehension, and built-in functions. Algorithm Define a list of numbers Iterate through the list and find numbers that are multiples of the desired number Store the positions of the multiples in a separate list Using List Comprehension List comprehension provides a concise way to find positions of multiples ? numbers = [2, 4, 6, 8, 10, 12, ...

Read More

HandCalcs Module Python

Atharva Shah
Atharva Shah
Updated on 27-Mar-2026 1K+ Views

HandCalcs is a Python library that automatically generates LaTeX-formatted mathematical equations from Python calculations. It creates beautiful, hand-written-style mathematical documentation directly from your Python code, making it essential for technical reports and scientific documentation. Installation Install HandCalcs using pip ? pip install handcalcs Basic Usage HandCalcs works primarily in Jupyter notebooks using the %%render magic command. Import the library and use the decorator to render calculations ? import handcalcs.render Example 1: Basic Arithmetic This example demonstrates simple numerical calculations with automatic LaTeX rendering ? %%render a ...

Read More

__subclasscheck__ and __subclasshook__ in Python

Tushar Sharma
Tushar Sharma
Updated on 27-Mar-2026 1K+ Views

Python provides powerful mechanisms for customizing inheritance behavior through two special methods: __subclasscheck__ and __subclasshook__. These methods allow you to define custom criteria for determining subclass relationships beyond traditional inheritance. Understanding __subclasscheck__ and __subclasshook__ By default, Python's issubclass() function checks the inheritance tree to determine class relationships. However, you can override this behavior using these special methods: __subclasscheck__(cls, subclass) − Called by issubclass() to test if a class is a subclass. Can be overridden to provide custom inheritance logic. __subclasshook__(cls, subclass) − Defined in abstract base classes (ABCs) to customize subclass checks. Called by the default ...

Read More
Showing 1261–1270 of 21,090 articles
« Prev 1 125 126 127 128 129 2109 Next »
Advertisements