Skip to content

Instantly share code, notes, and snippets.

@socratesk
Created August 9, 2018 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save socratesk/438c9a98a5a2cea09a60388be26c3c14 to your computer and use it in GitHub Desktop.
Save socratesk/438c9a98a5a2cea09a60388be26c3c14 to your computer and use it in GitHub Desktop.
import pandas as pd
incExpDF = pd.DataFrame({'id' : [101, 102, 103, 104, 105],
'familyCnt' : [2, 4, 3, 3, 5],
'totalInc' : [68000, 72000, 34000, 44000, 52000],
'totalExp' : [48000, 66000, 33000, 41000, 50000]})
incExpDF['incPerPerson'] = incExpDF['totalInc'] / incExpDF['familyCnt']
incExpDF['expPerPerson'] = incExpDF['totalExp'] / incExpDF['familyCnt']
incExpDF['savingsPerPerson'] = incExpDF['incPerPerson'] - incExpDF['expPerPerson']
print(incExpDF)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment