import pandas as pd
def winner_votes(df):
gdf = df.groupby(df.iloc[:,2:].idxmax(axis=1)).sum()['electors'].reset_index()
return gdf.loc[gdf['electors'].idxmax()].to_list()
df_in = pd.DataFrame([['Winterfell', 3, 0.6, 0.3, 0.1],
['Riverrun', 5, 0.3, 0.2, 0.5],
['Vaes Dothrak', 2, 0.2, 0.5, 0.5]], columns=['state', 'electors',
'Arya Stark',
'Tyrion Lannister',
'Deineris Targarien'])
print(winner_votes(df_in))
# expected - ["Deineris Targarien", 7]
# got - ['Deineris Targarien', 5]
winner = df_in.groupby(df_in.iloc[:,2:999].idxmax(axis=1)).sum()['electors'].idxmax()
return df_in[df_in[winner] == df_in.max()]['electors'].sum()
df = pd.DataFrame([['Winterfell', 3, 0.6, 0.3, 0.1],
['Riverrun', 5, 0.3, 0.2, 0.5],
['Vaes Dothrak', 2, 0.2, 0.5, 0.5]], columns=['state', 'electors',
'Arya Stark',
'Tyrion Lannister',
'Deineris Targarien'])
def winner_votes(df_in):
df = df_in.groupby(['state', 'electors'], sort=False).first()
df.sort_index(axis=1, inplace=True)
df['winner'] = df.idxmax(axis=1)
return df.groupby('winner').first()
df = pd.DataFrame([['Winterfell', 3, 0.6, 0.3, 0.1],
['Riverrun', 5, 0.3, 0.2, 0.5],
['Vaes Dothrak', 2, 0.2, 0.5, 0.5]], columns=['state', 'electors',
'Arya Stark',
'Tyrion Lannister',
'Deineris Targarien'])
print(winner_votes(df))
ctrl = df[df['group'] == 'A']['converted'] # pandas Series, control group
test = df[df['group'] == 'B']['converted'] # pandas Series, test group
t = (np.mean(ctrl) - np.mean(test)) / np.sqrt(
np.std(ctrl, ddof = 1) ** 2 / ctrl.size + (np.std(test, ddof = 1) ** 2) / test.size
)
description_l = "%{}%".format( text.lower() )
results = await db.execute("SELECT description FROM articles WHERE description_l LIKE ?",[description_l])