To perform a row-wise summation of a Pandas DataFrame in Python, you can use the sum()
function along with the axis
parameter set to 1.
Here's an example of how you can do it:
main.py237 chars14 lines
Output:
main.py37 chars5 lines
In the above example, we create a sample DataFrame df
with three columns A
, B
, and C
. We then use the sum()
function with axis=1
to perform the row-wise summation and store the result in the row_sum
variable. Finally, we print the row_sum
to display the row-wise summation of the DataFrame.
Note that the result is a Pandas Series object with row indices as 0, 1, and 2, corresponding to the rows of the DataFrame.
gistlibby LogSnag