下面的数组是我的模型的结果,如何将它追加到我的数据框的最后一列
def key_to_map(key):
m = {}
alphabet = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
while(key):
k = key.pop()
m[k] = [alphabet.pop()] + m.get(k, [])
return m
def decrypt(ciphertext, key_map, plaintext):
if not ciphertext:
yield plaintext
else:
current = ciphertext[0]
for possibility in key_map.get(current, [current]):
for plain in decrypt(ciphertext[1: ], key_map, plaintext + possibility):
yield plain
def main():
ciphertext = input("Entre com o texto cifrado: ").upper()
key = list("DEFGHIJKLMNOPQRSTUVWXYZABC")
key_map = key_to_map(key)
result = list(decrypt(ciphertext, key_map, ""))
print("Resultados Possíveis: ")
print(result)
for x in result:
print(x)
print("Quantidade de Hipóteses Possíveis: {}".format(len(result)))
if __name__ == "__main__":
main()
数据框数据:
In[] logireg.predict(X.head(5))
Out[] array([0, 0, 0, 1, 0], dtype=int64)
预期产出
age job month
33 blue apr
56 admin jun
37 tech aug
76 retired jun
56 service may
用于循环或zip功能?
答案 0 :(得分:1)
您可以直接将其分配给数据框列。假设您的数据框在此处调用dataframe
:
predictions = logireg.predict(X.head(5))
dataframe['predict'] = predictions