text_plain_output_5.png text_plain_output_9.png application_vnd.jupyter.stderr_output_4.png application_vnd.jupyter.stderr_output_6.png application_vnd.jupyter.stderr_output_8.png application_vnd.jupyter.stderr_output_10.png text_plain_output_3.png text_plain_output_7.png text_plain_output_2.png text_plain_output_1.png text_plain_output_11.png
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import pandas as pd
names_data = pd.read_csv('../input/NationalNames.csv')
frequent_names = names_data[names_data['Count'] > 1000]
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']))
yearly_ambiguity = ambiguity_data.groupby(level='Year')

print('Average ambiguity: %s\n' % str(ambiguity_data.mean()))
print('Average by year: %s\n' % str(yearly_ambiguity.mean()))
print('Most ambiguous by year: %s' % str(yearly_ambiguity.idxmax().apply(lambda x: x[1])))