Categories
Python Answers

How to insert list into a cell with Python Pandas?

Spread the love

Sometimes, we want to insert list into a cell with Python Pandas.

In this article, we’ll look at how o insert list into a cell with Python Pandas.

How to insert list into a cell with Python Pandas?

To insert list into a cell with Python Pandas, we use at to get the row and column we want to insert the list into.

Then we assign the list to it.

For instance, we write

df['B'] = df['B'].astype('object')
df.at[1, 'B'] = [1, 2, 3]

to convert column B to an object with astype.

And then we assign the value at row index 1 and column B to a list with

df.at[1, 'B'] = [1, 2, 3]

Conclusion

To insert list into a cell with Python Pandas, we use at to get the row and column we want to insert the list into.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *