Articles on Trending Technologies

Technical articles with clear explanations and examples

Write a program in Python to shift the first column and get the value from the user, if the input is divisible by both 3 and 5 and then fill the missing value

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

This article demonstrates how to shift DataFrame columns and conditionally fill missing values based on user input. We'll shift the first column to the right and fill the new empty column with a user-provided value only if it's divisible by both 3 and 5. Understanding Column Shifting The shift() method with axis=1 shifts columns horizontally. When shifting right, the first column becomes empty and needs to be filled. Creating the DataFrame import pandas as pd data = pd.DataFrame({ 'one': [1, 2, 3], 'two': [10, 20, 30], ...

Read More

Write a program in Python to calculate the default float quantile value for all the element in a Series

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

A quantile represents the value below which a certain percentage of data falls. In pandas, the quantile() method calculates quantile values for a Series, with 0.5 being the default (median). Understanding Quantiles The quantile value of 0.5 represents the median − the middle value when data is sorted. For a Series with values [10, 20, 30, 40, 50], the 0.5 quantile (median) is 30.0. Syntax Series.quantile(q=0.5, interpolation='linear') Parameters: q − Float between 0 and 1 (default is 0.5) interpolation − Method to use when quantile lies between two data points ...

Read More

Write a program in Python to count the records based on the designation in a given DataFrame

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

To count records based on designation in a pandas DataFrame, we use the groupby() method combined with count(). This groups rows by designation and counts occurrences in each group. Creating the DataFrame Let's start by creating a sample DataFrame with employee data ? import pandas as pd data = { 'Id': [1, 2, 3, 4, 5], 'Designation': ['architect', 'scientist', 'programmer', 'scientist', 'programmer'] } df = pd.DataFrame(data) print("DataFrame is:") print(df) DataFrame is: Id Designation 0 1 architect 1 ...

Read More

Write a program in Python to store the city and state names that start with 'k' in a given DataFrame into a new CSV file

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

When working with pandas DataFrames, you often need to filter data based on specific criteria and save the results to a file. This example demonstrates how to filter cities and states that start with 'K' and export them to a CSV file. Problem Statement Given a DataFrame with City and State columns, we need to find rows where both the city name and state name start with 'K', then save these filtered results to a new CSV file. Solution Approach To solve this problem, we will follow these steps: Create a DataFrame with city ...

Read More

Write a Python code to select any one random row from a given DataFrame

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

Sometimes you need to select a random row from a Pandas DataFrame for sampling or testing purposes. Python provides several approaches to accomplish this task using iloc with random index generation or the sample() method. Sample DataFrame Let's start with a sample DataFrame to demonstrate the methods ? import pandas as pd data = {'Id': [1, 2, 3, 4, 5], 'Name': ['Adam', 'Michael', 'David', 'Jack', 'Peter']} df = pd.DataFrame(data) print("DataFrame is") print(df) DataFrame is Id Name 0 1 Adam ...

Read More

How can Tensorflow be used to train the model using Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 289 Views

TensorFlow provides the fit() method to train machine learning models. This method requires training data, validation data, and the number of epochs (complete passes through the dataset) to optimize the model's parameters. Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks? Setting up the Environment We are using Google Colaboratory to run the below code. Google Colab provides free access to GPUs and requires zero configuration, making it ideal for machine learning experiments. Training the Model The model.fit() method trains the neural network by iteratively adjusting weights based on ...

Read More

How can Tensorflow be used to create a sequential model using Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 272 Views

A sequential model in TensorFlow can be created using the Keras Sequential API, which stacks layers linearly where each layer has exactly one input and one output tensor. This is ideal for building straightforward neural networks like convolutional neural networks (CNNs). Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks? Creating a Sequential CNN Model Let's create a sequential model for image classification with convolutional and dense layers − import tensorflow as tf from tensorflow.keras import layers, Sequential print("Sequential model is being created") # Define image dimensions ...

Read More

How can Tensorflow be used to standardize the data using Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 521 Views

TensorFlow provides powerful tools for data preprocessing, including standardization of image data. The flowers dataset contains thousands of flower images across 5 classes, making it perfect for demonstrating data normalization techniques using TensorFlow's preprocessing layers. Data standardization is crucial for neural networks as raw pixel values (0-255) can cause training instabilities. We'll use TensorFlow's Rescaling layer to normalize pixel values to the [0, 1] range. Setting Up the Environment We are using Google Colaboratory to run the code. Google Colab provides free access to GPUs and requires zero configuration, making it ideal for TensorFlow projects. Creating ...

Read More

How can Tensorflow be used to pre-process the flower training dataset?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 284 Views

TensorFlow can preprocess the flower training dataset using the Keras preprocessing API. The image_dataset_from_directory method efficiently loads images from directories and creates validation datasets with proper batching and image resizing. Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks? About the Flower Dataset The flower dataset contains 3, 700 images of flowers divided into 5 classes: daisy, dandelion, roses, sunflowers, and tulips. Each class has its own subdirectory, making it perfect for the image_dataset_from_directory function. Preprocessing the Dataset Here's how to preprocess the flower dataset using TensorFlow's Keras preprocessing ...

Read More

How can Tensorflow be used to split the flower dataset into training and validation?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 538 Views

The flower dataset can be split into training and validation sets using TensorFlow's Keras preprocessing API. The image_dataset_from_directory function provides an easy way to load images from directories and automatically split them into training and validation sets. Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks? About the Flower Dataset The flower dataset contains approximately 3, 700 images of flowers organized into 5 subdirectories, with one subdirectory per class: daisy, dandelion, roses, sunflowers, and tulips. This structure makes it perfect for supervised learning tasks. Splitting the Dataset Here's how ...

Read More
Showing 5451–5460 of 61,299 articles
« Prev 1 544 545 546 547 548 6130 Next »
Advertisements