Answer the question
In order to leave comments, you need to log in
How to update pandas dataframe with data from dictionary?
There is a dataframe:
test_dict = {
'A':1,
'B':2,
'C':3,
'D':None
}
test_dict_df = pd.DataFrame.from_dict(test_dict.items())
test_dict_df = test_dict_df.rename(columns={0:'name', 1:'value'})
update_dict = {'D':33}
for i,x in update_dict.items():
test_dict_df[test_dict_df['name']==i]['value'] = x
Answer the question
In order to leave comments, you need to log in
solution from SO:
```
t = test_dict_df["name"].map(update_dict).dropna()
test_dict_df.loc[t.index, "value"] = t
```
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question