猿问

创建两个 numpy.ndarray 的字典?

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


守候你守候我
浏览 256回答 3
3回答

白猪掌柜的

arrays不需要转换为,iloc用于选择第一列zip:new_dict = dict(zip(df.iloc[:, 0], df1.iloc[:, 0]))或按名称选择列:new_dict = dict(zip(df['col'], df1['col']))
随时随地看视频慕课网APP

相关分类

Python
我要回答