Trying to do multiple assigments with a filtered dataset I encountered a strange behavior I cannot explaim myself. My Testdata:
import pandas as pd
wert = 2.5
df = pd.DataFrame([['Test', 12, None, None], ['Test2', 15, None, None]], columns=['A','B','C','D'])
My first question occured executing this line of code:
df.loc[(df['A'] == 'Test'), ['D']] = df['B'] * wert
the filter is only on the left side so how does df['B'] knows where to assign the values? I thought df['B'] should be filtered as well but this is obviously not neccessary. So I stepped forward doing multiple assignment with condition and tried to execute this line:
df.loc[(df['A'] == 'Test'), ['C', 'D']] = [1, df['B'] * wert]
Now I get an error ValueError: cannot set using a list-like indexer with a different length than the value. My explanation would be that the array df['B'] is longerthan df.loc[df['A']=='Test) but since this worked fine in example 1 this cannot be the exlanation. Could anyone tell me why this is not working and giving me this error?