def calculate(imTree): trades = imTree.Crif.Sensitivities.keys() standaloneTrees = {} standaloneMatrix = imTree.FlatTree.copy(deep=True) standaloneMatrix.set_index([ 'Im Model', 'Silo', 'RiskClass', 'SensitivityType', 'Bucket', 'WeightedSensitivity' ], inplace=True) standaloneMatrix.drop(columns=['ExposureAmount'], inplace=True) for t in trades: standaloneFlatTree = GenerateCsvString.parseToFlatCsv( Simm.calculateTreeStandard(imTree.Crif.Sensitivities[t], imTree.CalculationCurrency)) standaloneFlatTree = StringIO(standaloneFlatTree) standaloneFlatTree = ResultTrees.ImTreeUtil.read_csv( standaloneFlatTree) standaloneFlatTree.set_index([ 'Im Model', 'Silo', 'RiskClass', 'SensitivityType', 'Bucket', 'WeightedSensitivity' ], inplace=True) standaloneFlatTree.drop(columns=['Level'], inplace=True) standaloneFlatTree.rename(columns={'ExposureAmount': t}, inplace=True) standaloneMatrix = pd.merge(standaloneMatrix, standaloneFlatTree, how='left', on=[ 'Im Model', 'Silo', 'RiskClass', 'SensitivityType', 'Bucket', 'WeightedSensitivity' ]) standaloneMatrix.drop(columns=['Level'], inplace=True) standaloneMatrix.reset_index(drop=True, inplace=True) for key, value in imTree.nodes.items(): standaloneAllocation = standaloneMatrix.iloc[value.data.rowNumber] standaloneAllocation.dropna(inplace=True) value.data.standaloneAllocation = standaloneAllocation imTree.hasStandaloneAllocation = True return imTree
print(text) columns = [ "byr",# (Birth Year)", "iyr",# (Issue Year)", "eyr",# (Expiration Year)", "hgt",# (Height)", "hcl",# (Hair Color)", "ecl",# (Eye Color)", "pid",# (Passport ID)", "cid"]# (Country ID)" data=pd.read_csv(data, names= ["Raw", "byr","iyr","eyr","hgt","hcl","ecl","pid","cid"], header=None) def datacheck(check): if check.find(col) > 0: #magic = r'\b'+col+'\S*' magic = col+'\S+' return str(re.search(magic, check)[0]).replace(col+":","") else: return for col in columns: data[col]=data.apply(lambda row: datacheck(row.Raw), axis=1) data = data.drop(columns=["Raw"]) #print(data) data['missing'] = data.apply(lambda x: 8-x.count(), axis=1) print(data['missing'].value_counts()) print(data)