SHARE
TWEET

Untitled

a guest Feb 25th, 2020 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. children_data = clients_data.loc[:, ['children', 'debt']]
  2.  
  3. def children_count(_count):
  4.     if _count == 0:
  5.         return 'нет детей'
  6.     if _count == 1:
  7.         return 'один ребёнок'
  8.     if _count == 2:
  9.         return 'два ребёнка'
  10.     return 'многодетный'
  11.  
  12. def is_debt(debt):
  13.     if debt == 0:
  14.         return 'no_debt'
  15.     return 'in_debt'
  16.  
  17. children_data['children_count'] = children_data['children'].apply(children_count)
  18. children_data['debt'] = children_data['debt'].apply(is_debt)
  19. children_pivot = children_data.pivot_table(index='children_count', columns='debt', aggfunc='count')
  20.  
  21. children_pivot['debt_percent'] = children_pivot['children', 'in_debt'] / (children_pivot['children', 'in_debt'] +
  22.                                                                         children_pivot['children', 'no_debt'])
  23.  
  24. print(children_pivot.sort_values(by='debt_percent'))
  25.  
  26. family_data = clients_data.merge(family_status_dict, on='family_status_id', how='left')
  27. family_data = family_data.loc[:, ['family_status', 'debt']]
  28. family_data['debt'] = family_data['debt'].apply(is_debt)
  29. print(family_data['debt'].value_counts())
  30.  
  31. family_pivot = family_data.pivot_table(index='family_status', columns='debt', aggfunc='count')
  32. print(family_pivot)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top