Skip to content

Instantly share code, notes, and snippets.

@andersonfrailey
Created February 3, 2018 02:03
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 andersonfrailey/7ccac5057b413cb44a8d3e80d4eb0e44 to your computer and use it in GitHub Desktop.
Save andersonfrailey/7ccac5057b413cb44a8d3e80d4eb0e44 to your computer and use it in GitHub Desktop.
def find_perc(data, bin_name):
# find percentatge for each type of effect
sum_wt = data.s006.sum()
# tax liability decrease of > $500
large_cut = tc.zsum(data.s006[data['change'] < -500]) / float(sum_wt)
# tax liability decrease of $100-500
small_cut = tc.zsum(data.s006[(data['change'] >= -500) & (data['change'] <= -100)]) / float(sum_wt)
# tax liability change of less than $100
no_change = tc.zsum(data.s006[(data['change'] > -100) & (data['change'] < 100)]) / float(sum_wt)
# tax liability increase of $100-500
small_increase = tc.zsum(data.s006[(data['change'] >= 100) & (data['change'] <= 500)]) / float(sum_wt)
# tax liability increase of > $500
large_increase = tc.zsum(data.s006[(data['change'] > 500)]) / float(sum_wt)
# find edges for the bar chart
bottom = 0.0
total_perc = bottom
edge_name_list = [bottom, large_cut, small_cut, no_change, small_increase, large_increase]
edges_list = []
for item in edge_name_list:
total_perc += item
edges_list.append(total_perc)
plot_data = pd.DataFrame({'bottom': [edges_list[0]],
'large_cut': [edges_list[1]],
'small_cut': [edges_list[2]],
'no_change': [edges_list[3]],
'small_inc': [edges_list[4]],
'large_inc': [edges_list[5]],
'name': [bin_name]})
return ColumnDataSource(plot_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment