text_plain_output_1.png
from sklearn.preprocessing import MinMaxScaler

import pandas as pd

df = pd.read_csv('../input/NationalNames.csv')

df['Decade'] = df['Year'].apply(lambda x: x - x % 10)

df_pivot = df.pivot_table(values='Count', index=['Decade', 'Name', 'Gender'], aggfunc='sum')
new_df = pd.DataFrame()
new_df['Decade'] = df_pivot.index.get_level_values('Decade')
new_df['Name'] = df_pivot.index.get_level_values('Name')
new_df['Gender'] = df_pivot.index.get_level_values('Gender')
new_df['Count'] = df_pivot.values

decadeList = list(new_df['Decade'].unique())
boys_percentileList = []
girls_percentileList = []
boys_df = new_df[new_df['Gender'] == 'M'].copy()
girls_df = new_df[new_df['Gender'] == 'F'].copy()
for i in decadeList:
    scaler = MinMaxScaler()
    boys_percentileList.extend(scaler.fit_transform(boys_df[boys_df['Decade'] == i][['Count']]))
    girls_percentileList.extend(scaler.fit_transform(girls_df[girls_df['Decade'] == i][['Count']]))
boys_df['decade_percentile'] = boys_percentileList
girls_df['decade_percentile'] = girls_percentileList
new_df = boys_df.append(girls_df)
new_df['decade_percentile'] = new_df['decade_percentile'].apply(lambda x: float(x) * 100)
new_df.sort_index(inplace=True)
del boys_df
del girls_df

new_df[new_df['decade_percentile'] >= 99.0]