import numpy as np
import pandas as pd
columns = ['id', 'A', 'B', 'C']
index = np.arange(3)
df = pd.DataFrame(np.random.randn(3,4), columns=columns, index=index)
weights = {'A': 0.10, 'B': 1.00, 'C': 1.50}
我需要在每個「單元格」中使用相應的權重(不包括第一列)多個值。例如:使用'lookup'乘以兩個python數組
df.at[0,'A'] * weights['A']
df.at[0,'B'] * weights['B']
什麼是最有效的方式來做到這一點,並在新的DataFrame中產生結果?
這是否假定權重數組與df列的順序相同?在我的實際數據,他們不會,所以我需要一種方法來查找相應的權重 – Carl
@weights不是一個數組,它是一個'dict' –
請看看我的udpates,看看這是你所追求的。 – Allen