Skip to content

How to append a dictionary with multiple keys to a dataframe

I am trying to append a dictionary to my DataFrame.

This is how the DataFrame looks:

NR   RS   BP
0471 10   11.41
0652 10   11.50
0650 20   11.35
6519 40   11.06

And this is the dictionary:

bpDict = {"nr":["0471","0652","0650","6519"],

I need to append this dictionary to my df. I know how to do it when I append one column (using map) but this is not going to work here.

Any ideas on how to append this?



You can use the merge() method from Pandas dataframes. You can do something like that :

df = pd.DataFrame({
    "BP":[11.41, 11.50, 11.35, 11.06],
bpDict = {"nr":["0471","0652","0650","6519"],
df_2 = pd.DataFrame(bpDict)
df.merge(df_2, on="nr")
1 People found this is helpful