Python的大熊猫 - 更新行基于索引的字典,列

问题描述:

我有一个空列的数据帧,并与基于索引我想更新的空列相应的字典,柱:Python的大熊猫 - 更新行基于索引的字典,列

import pandas as pd  
import numpy as np 

dataframe = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9], [4, 6, 2], [3, 4, 1]]) 
dataframe.columns = ['x', 'y', 'z'] 
additional_cols = ['a', 'b', 'c'] 

for col in additional_cols: 
    dataframe[col] = np.nan 

    x y z a b c 
0 1 2 3   
1 4 5 6   
2 7 8 9   
3 4 6 2   
4 3 4 1   

for row, column in x.iterrows(): 
    #caluclations to return dictionary y 
    y = {"a": 5, "b": 6, "c": 7} 
    df.loc[row, :].map(y) 

基本上使用列X,Y,Z进行计算后,我想更新列A,b,C表示同一行:)

我可以用一个函数本身,而是尽可能的大熊猫库和方法数据框对象我不知道......

def update_row_with_dict(dictionary, dataframe, index): 
    for key in dictionary.keys(): 
    dataframe.loc[index, key] = dictionary.get(key)