Server Side Programming Articles

Page 485 of 2109

How can scikit-learn library be used to get the resolution of an image in Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 509 Views

Data pre-processing refers to the task of gathering data from various resources into a common format. Since real-world data is never ideal, images may have alignment issues, clarity problems, or incorrect sizing. The goal of pre-processing is to remove these discrepancies. To get the resolution of an image, we use the shape attribute. After reading an image, pixel values are stored as a NumPy array. The shape attribute returns the dimensions of this array, representing the image resolution. Reading and Getting Image Resolution Let's see how to upload an image and get its resolution using scikit-image library ...

Read More

How to get the mean of columns that contains numeric values of a dataframe in Pandas Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 1K+ Views

Sometimes, you may need to calculate the mean values of specific columns or all columns containing numeric data in a pandas DataFrame. The mean() function automatically identifies and computes the mean for numeric columns only. The term mean refers to finding the sum of all values and dividing it by the total number of values in the dataset (also called the arithmetic average). Basic Example Let's create a DataFrame with mixed data types and calculate the mean of numeric columns − import pandas as pd # Create a DataFrame with mixed data types data ...

Read More

How to get the sum of a specific column of a dataframe in Pandas Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 1K+ Views

Sometimes, it may be required to get the sum of a specific column in a Pandas DataFrame. This is where the sum() function can be used to perform column-wise calculations. The column whose sum needs to be computed can be accessed by column name or index. Let's explore different approaches to calculate the sum of a specific column. Creating a Sample DataFrame First, let's create a DataFrame with sample data ? import pandas as pd my_data = { 'Name': pd.Series(['Tom', 'Jane', 'Vin', 'Eve', 'Will']), 'Age': pd.Series([45, ...

Read More

How to delete a column of a dataframe using the 'pop' function in Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 381 Views

A Pandas DataFrame is a two-dimensional data structure where data is stored in tabular format with rows and columns. It can be visualized as an SQL table or Excel sheet. The pop() function provides an efficient way to delete a column while simultaneously returning its values. Syntax DataFrame.pop(item) Parameters: item − The column name to be removed Returns: The removed column as a Series Example Let's create a DataFrame and delete a column using the pop() function ? import pandas as pd my_data = { ...

Read More

How can a column of a dataframe be deleted in Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 192 Views

A DataFrame is a two-dimensional data structure where data is stored in tabular format with rows and columns. It can be visualized as an SQL table or Excel sheet. There are several methods to delete columns from a DataFrame in Python pandas. Using the del Operator The del operator permanently removes a column from the DataFrame ? import pandas as pd my_data = { 'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35], 'City': ['New York', 'London', 'Paris'], 'Salary': [50000, ...

Read More

Explain how a dataframe structure can be created using list of dictionary values in Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 185 Views

A DataFrame is a two-dimensional data structure where data is stored in tabular format with rows and columns. It can be visualized as an SQL table or Excel sheet representation. You can create a DataFrame using the following constructor ? pd.DataFrame(data, index, columns, dtype, copy) The parameters data, index, columns, dtype, and copy are optional. Creating DataFrame from List of Dictionaries When you pass a list of dictionaries to DataFrame, the dictionary keys become column names by default. Each dictionary represents a row of data ? import pandas as pd ...

Read More

What happens if the specified index is not present in the series Python Pandas?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 701 Views

When accessing pandas Series elements using custom index values, you use the syntax series_name['index_value']. If the specified index exists, the corresponding data is returned. However, if the index is not present in the series, pandas raises a KeyError. Example: Accessing Non-existent Index Let's see what happens when we try to access an index that doesn't exist ? import pandas as pd my_data = [34, 56, 78, 90, 123, 45] my_index = ['ab', 'mn', 'gh', 'kl', 'wq', 'az'] my_series = pd.Series(my_data, index=my_index) print("The series contains following elements:") print(my_series) print("Attempting to access non-existent index 'mm':") print(my_series['mm']) ...

Read More

How to retrieve multiple elements from a series when the index is customized Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 1K+ Views

When working with Pandas Series that have customized index values, you can retrieve multiple elements by passing a list of index values. This allows flexible data access using meaningful labels instead of numeric positions. Basic Syntax To access multiple elements from a series with custom index ? series_name[['index1', 'index2', 'index3']] Note the double square brackets [[]] − the inner brackets create a list of index values, while the outer brackets perform the indexing operation. Example import pandas as pd my_data = [34, 56, 78, 90, 123, 45] my_index = ['ab', ...

Read More

Explain how series data structure in Python can be created using scalar/constant values?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 348 Views

A Pandas Series can be created using scalar or constant values. When you pass a scalar value to the Series() constructor, that value is repeated across all entries. The number of entries depends on whether you specify an index. Creating Series with Scalar Value and Custom Index When you provide both a scalar value and an index, the scalar is repeated for each index position ? import pandas as pd my_index = ['ab', 'mn', 'gh', 'kl'] my_series = pd.Series(7, index=my_index) print("Series created using scalar value with custom index:") print(my_series) Series created ...

Read More

Program to check number of requests that will be processed with given conditions in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 538 Views

When building web applications, we often need to implement rate limiting to prevent abuse. This problem demonstrates how to process requests with both per-user and global rate limits within a 60-second sliding window. We have a list of requests where each contains [uid, time_sec] representing a user ID and timestamp. We need to enforce two constraints: u (maximum requests per user in 60 seconds) and g (maximum global requests in 60 seconds). Requests at the same timestamp are processed by lowest user ID first. Example Given requests = [[0, 1], [1, 2], [1, 3]], u = 1, ...

Read More
Showing 4841–4850 of 21,090 articles
« Prev 1 483 484 485 486 487 2109 Next »
Advertisements