Created
August 19, 2017 09:53
-
-
Save saahil1292/29c23f122b53b6dda1be7147bf044cf7 to your computer and use it in GitHub Desktop.
New features in the dataset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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