Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

add values of two columns pandas

df['sum'] = df['a'] + df['b']  # sum is a new column
Comment

add values from 2 columns to one pandas

df['Fruit Total']= df.iloc[:, -4:-1].sum(axis=1)
print (df)
   Apples  Bananas  Grapes  Kiwis  Fruit Total
0     2.0      3.0     NaN    1.0          5.0
1     1.0      3.0     7.0    NaN         11.0
2     NaN      NaN     2.0    3.0          2.0
Comment

PREVIOUS NEXT
Code Example
Python :: python3 lowercase 
Python :: # write json file 
Python :: How to Crack PDF Files in Python - Python Cod 
Python :: remove duplicates from tuple python 
Python :: python hash() seed 
Python :: tensorflow to numpy 
Python :: django queryset exists 
Python :: how to make python open an application on mac 
Python :: python math operators 
Python :: matplotlib twinx legend 
Python :: mean squared error 
Python :: querydict instance is immutable 
Python :: python get array length 
Python :: create dict from two lists 
Python :: cumulative frequency for python dataframe 
Python :: save object pickle python 
Python :: how to reset username and password in django admin 
Python :: split list in pd dataframe into rows 
Python :: mypy clear cache 
Python :: python 3.7.9 download 
Python :: how to clear the list in python 
Python :: python finally keyword 
Python :: create a virtualenv python3 
Python :: python isinstance 
Python :: python extract string 
Python :: python @property 
Python :: pillow image from array 
Python :: pandas number format 
Python :: django queryset to list 
Python :: how to let only admins do a command in discord.py 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =