Skip to content

Instantly share code, notes, and snippets.

@saahil1292
Created August 19, 2017 09:53
Show Gist options
  • Save saahil1292/29c23f122b53b6dda1be7147bf044cf7 to your computer and use it in GitHub Desktop.
Save saahil1292/29c23f122b53b6dda1be7147bf044cf7 to your computer and use it in GitHub Desktop.
New features in the dataset
# battles['attcker_number'] = []
@timeit
def new_features(dataframe1, dataframe2):
''' Creates New Features in both the dataframes
Parameters
-----------
method: dataframes
Return
-----------
None
'''
dataframe1.loc[:, 'attacker_count'] = (4 - battles[['attacker_1','attacker_2', 'attacker_3', \
'attacker_4']].isnull().sum(axis=1))
dataframe1.loc[:, 'defender_count'] = (4 - battles[['defender_1','defender_2', 'defender_3', \
'defender_4']].isnull().sum(axis=1))
dataframe1.loc[:, 'att_comm_count'] = [len(x) if type(x) == list else np.nan for \
x in battles.attacker_commander.str.split(',')]
dataframe2.loc[:, 'no_of_books'] = character_predictions[[x for x in \
character_predictions.columns \
if x.startswith('book')]].sum(axis=1)
new_features(battles, character_predictions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment