def gini_accum(data, index): #~ data = raw_data.set_index([raw_data['timestamp'].dt.to_period('M'), raw_data.index]) monthly_data = data.groupby(pd.Grouper(key='timestamp', freq='MS')) if index is not None: gini_accum_df = pd.Series(index=index) else: gini_accum_df = pd.Series(index=monthly_data.size().index) indices = gini_accum_df.index i = 0 accum_data = pd.DataFrame() for name, group in monthly_data: # Accumulate data so far accum_data = accum_data.append(group) # Get contributions per contributor, sort them # and make it a list to call to gini_coeff() values = contributions_per_author(accum_data) \ .tolist() n_users = len(values) if (n_users) < MINIMAL_USERS_GINI: gini_accum_df[indices[i]] = np.NaN else: gini_accum_df[indices[i]] = ineq.gini_corrected(values, n_users) i = i + 1 return gini_accum_df
def calculate_gini_user_talk_edits(self): if 'user_talks' in self.graph.vs.attributes() and 'gini_user_talks'\ not in self.graph.attributes(): gini = ineq.gini_corrected(self.graph.vs['user_talks']) if gini is not np.nan: self.graph['gini_user_talks'] = f"{gini:.2f}" else: self.graph['gini_user_talks'] = 'nan'
def calculate_gini_closeness(self): if 'closeness' in self.graph.vs.attributes() and 'gini_closeness'\ not in self.graph.attributes(): gini = ineq.gini_corrected(self.graph.vs['closeness']) if gini is not np.nan: self.graph['gini_closeness'] = f"{gini:.2f}" else: self.graph['gini_closeness'] = 'nan'
def calculate_gini_betweenness(self): if 'betweenness' in self.graph.vs.attributes() and 'gini_betweenness'\ not in self.graph.attributes(): gini = ineq.gini_corrected(self.graph.vs['betweenness']) value = 'nan' if gini is not np.nan: value = f"{gini:.2f}" self.graph['gini_betweenness'] = value
def calculate_gini_degree(self): if self.graph.is_directed() and 'gini_indegree' not in\ self.graph.attributes(): gini = ineq.gini_corrected(self.graph.vs['indegree']) value = 'nan' if gini is not np.nan: value = value = f"{gini:.2f}" self.graph['gini_indegree'] = value gini = ineq.gini_corrected(self.graph.vs['outdegree']) value = 'nan' if gini is not np.nan: value = value = f"{gini:.2f}" self.graph['gini_outdegree'] = value elif 'gini_degree' not in self.graph.attributes(): gini = ineq.gini_corrected(self.graph.vs['degree']) value = 'nan' if gini is not np.nan: value = value = f"{gini:.2f}" self.graph['gini_degree'] = value