DEV Community

Nilotpal Choudhury
Nilotpal Choudhury

Posted on

Answer: Add values to an existing dataframe from list of tuples

You can use double [] with columns names, join or concat:

df = pd.DataFrame({'column':range(5)})
print (df)
   column
0       0
1       1
2       2
3       3
4       4

l = [('l1', 0.966797), ('l1', 0.998047), 
     ('l2', 0.978516), ('l2', 0.998047), ('l3', 0.972656)]

df[['s','p']] = pd.DataFrame(l)

df = df.join(pd.DataFrame(l,columns=['s','p']))

df = pd.concat([df, pd.DataFrame(l,columns=['s','p'])],

Top comments (0)