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:
partspec_insert
is created by selecting the specified columns from the original data framedf
.- The
loc
method is used to locate rows whereSpecTypeId
is not equal to 5 and update theUSL
andLSL
columns tonull
(represented bynp.nan
in pandas).
No comments:
Post a Comment