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 to 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 can use at.

For instance, we write

df = pd.DataFrame(data={'A': [1, 2, 3], 'B': ['x', 'y', 'z']})
df.at[1, 'B'] = ['m', 'n']

to create the df data frame with the DataFrame class called with a dict.

Then we use df.at[1, 'B'] to get the value at column B with index and assign ['m', 'n'] to it.

Conclusion

To insert list into a cell with Python Pandas, we can use at.

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 *