text_plain_output_1.png image_output_1.png
import pandas as pd

import math
import pandas as pd
names_data = pd.read_csv('../input/NationalNames.csv')
frequent_names = names_data[names_data['Count'] > 10]
indexed_names = frequent_names.set_index(['Year', 'Name'])['Count']
def ambiguity_measure(grouped_frame):
    return 2 * (1 - grouped_frame.max() / grouped_frame.sum())
ambiguity_data = ambiguity_measure(indexed_names.groupby(level=['Year', 'Name'])).rename('Ambiguity')
yearly_ambiguity = ambiguity_data.groupby(level='Year')
ambiguity_with_counts = ambiguity_data.to_frame().join(indexed_names.groupby(level=['Year', 'Name']).sum())
data_vs_years = ambiguity_with_counts.unstack(level='Year')
data_vs_years['Total'] = data_vs_years['Count'].sum(axis=1)

yearly_ambiguity.idxmax().apply(lambda x: x[1]).to_frame()