DEV Community

Nilotpal Choudhury
Nilotpal Choudhury

Posted on

1

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)

Quickstart image

Django MongoDB Backend Quickstart! A Step-by-Step Tutorial

Get up and running with the new Django MongoDB Backend Python library! This tutorial covers creating a Django application, connecting it to MongoDB Atlas, performing CRUD operations, and configuring the Django admin for MongoDB.

Watch full video →

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay