To add variables to a cell in Pandas DataFrame, you can use the .at[]
or .loc[]
accessor methods.
Here's an example code block:
main.py284 chars14 lines
In the code block above, we first create a sample dataframe df
. We then assign a value of 10
to the cell in row 1
and column B
using the .at[]
method. Similarly, we assign a value of 11
to the cell in row 2
and column C
using the .loc[]
method.
Finally, we print the updated dataframe to verify that the variables were successfully added to the respective cells.
gistlibby LogSnag