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.