Skip to main content

Update a certain rows in a column to NULL in Python data frame

 You can achieve this by using the pandas library in Python. Below is the code to update the USL and LSL columns to null when the SpecTypeId is not equal to 5.

import pandas as pd
import numpy as np

# Assuming df is your data frame
partspec_insert = df[['PartId', 'PartRev', 'TestCodeId', 'SpecTypeId', 'Nominal', 'USL', 'LSL', 'TMD', 'CustomerCoA']]

# Update USL and LSL to null when SpecTypeId is not equal to 5
partspec_insert.loc[partspec_insert['SpecTypeId'] != 5, ['USL', 'LSL']] = np.nan

# Display the updated data frame
print(partspec_insert)

Explanation:

  1. partspec_insert is created by selecting the specified columns from the original data frame df.
  2. The loc method is used to locate rows where SpecTypeId is not equal to 5 and update the USL and LSL columns to null (represented by np.nan in pandas).

Comments

Popular posts from this blog

Convex Lens Vs Concave Lens

What is a Lens A lens is a transparent object that transmits light across it, and its working principle depends on the   law of refraction (Snell’s law) . Applications: Concave Lens help with Far-Sight Convex Lens help with Near-Sight

Herbal Plants

Herbal plants to grow in home Different types of keerai ----- http://www.indiandietrecipes.com/2016/03/pictures-of-various-types-of-greens-or.html Pirandai ----good for bone joins---- https://youtu.be/k2DGubyXLAE Valarai Keerai Benifits ----- https://youtu.be/33HIfLJKTqA Sesma seeds ---- https://easyayurveda.com/2011/02/24/sesame-and-sesame-oil-benefits-total-ayurveda-details/

What is Verbal and Non-Verbal communication

TYPES OF COMMUNICATIONS: