我有两个 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/