Pandas Python How to make 2 values with equal len?

Viewed 43

Hi anyone can help on this? i got error when i run this:

conditions5 = [
    (data1['Payment Mode'] == '03')
]

choices5 = data1['Value Date']

data1['Valid From Date'] = np.select(conditions5, choices5, default ='') 
data1

Error: List of cases must be same length as list of conditions

I already tried using loc but the same error happen. How can i fix this?

data1.loc[data1['Payment Mode'] == '03'] = data1['Value Date']

Error: Must have equal len keys and value when setting with an iterable

2 Answers

Try np.where:

data1['valid from date'] = np.where(conditions5, data1['Value Date'], '')

Try this:

data1['Valid From Date'] = np.where(data1['Payment Mode'] == '03', data1['Value Date'], '')
Related