gpt4 book ai didi

python - 创建两个 numpy.ndarray 的字典?

转载 作者:太空宇宙 更新时间:2023-11-04 00:07:41 24 4
gpt4 key购买 nike

我有两个 numpy.ndarray

[[' THE OLD TESTAMENT ']
[' SEAN SONG ']
[' CITY WALK ']]

[[' This is the name of an Old Testament ']
[' Hello this is great ']
[' Wait the way you are doing ']]

我想将这些 ndarray 转换为字典。

 {
"THE OLD TESTAMENT": "This is the name of an Old Testament",
"SEAN SONG": "Hello this is great",
"CITY WALK": Wait the way you are doing
}

我正在使用下面写的代码

keys = df.as_matrix()
print (keys)
values = df1.as_matrix()
print (values)
new_dict = dict(izip(keys, values))

最佳答案

不需要转换为数组,使用iloc使用 zip 选择第一列:

new_dict = dict(zip(df.iloc[:, 0], df1.iloc[:, 0]))

或按名称选择列:

new_dict = dict(zip(df['col'], df1['col']))

关于python - 创建两个 numpy.ndarray 的字典?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53533819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com