I know how to use np.where() to add one column by 1 condition:
import pandas as pd
import numpy as np
df=pd.read_csv(file,nrows=5)
df['new_col1']= np.where(df['col1'] < '100', 1,2)
df.head()
output:
col1 col2 new_col1
0 1 3 1
1 2 4 1
what if I want to add 2 columns by the same condition:
df['new_col1'],df['new_col2']= np.where(df['col1'] < '100', (1,2),(3,4))
I want to add new_col1 and new_col2,the result are (1,2),(3,4)
When I tried this code, I received:
ValueError: too many values to unpack (expected 2)
The output should be:
col1 col2 new_col1 new_col2
0 1 3 1 3
1 2 4 1 3