import numpy as np
import pandas as pd
df = pd.DataFrame({'C': [500, 1200, 800, 1500]})
# Define your "Case" conditions
conditions = [
df['C'] > 1000, # Case 1
df['C'].between(500, 1000) # Case 2
]
# Define the outputs for each case
outputs = [
None, # Result for Case 1 (Clears the cell)
"Normal" # Result for Case 2
]
# np.select(conditions, outputs, default=Case_Else)
df['C_Status'] = np.select(conditions, outputs, default="Low")
print(df)
##########################################################
import pandas as pd
df = pd.read_excel(
'your_file.xlsx',
sheet_name='Sheet1',
usecols='B:F', # Select column range
skiprows=2, # Skip first 2 rows (starts reading at Excel row 3)
nrows=17 # Parse next 17 rows (from row 4 down to row 20)
)
###########################################################
import pandas as pd
# 1. Read your main data file
df_main = pd.read_excel('main_data.xlsx', sheet_name='Sheet1')
# 2. Read the 2-column Excel lookup table
# We convert it into a Python dictionary immediately using .to_dict()
df_lookup = pd.read_excel('lookup_table.xlsx', sheet_name='Sheet1')
lookup_dict = df_lookup.set_index('Key_A')['Value_B'].to_dict()
# 3. Use the 'A' column in your main data to supply/create the 'B' column
# The .fillna() block acts as your "Case Else" default value if no match is found
df_main['New_Column_B'] = df_main['Main_Column_A'].map(lookup_dict).fillna("No Match Found")
# 4. Save the updated main data
df_main.to_excel('mapped_output.xlsx', index=False)