简体   繁体   English

为什么 Python 3.7 在尝试 map(to_dict(pandas)) 时返回 memory 地址处的 map 对象?

[英]Why is Python 3.7 returning map objects at memory address when attempting map(to_dict(pandas))?

I start out with a pandas dataframe and a 1x8 numpy array of indices:我从一个 pandas dataframe 和一个 1x8 numpy 索引数组开始:

0  0,   0.0035
1  1,   0.0070
2  2,   0.0025
3  3,   0.0005
4  4,   0.0105
5  5,   0.0015
6  6,   0.0085
7  7,   0.0055
8  8,   0.0060
9  9,   0.0030

array([0, 2, 4, 8, 9, 5, 3, 1])

I'd like to return a mapping result with the array the "key":我想用数组“key”返回一个映射结果:

array([0.0035, 0.0025, 0.0105, 0.0060, 0.0030, 0.0015, 0.0005, 0.0070])

I attempt我尝试

new_list = [ map(float, nodes2[i]['node,prob'].split(',')) for i in indices[0]]
                 
for item in new_list:
    print(item)

which returns below.下面返回。

<map object at 0x000001B4898AFF88>
<map object at 0x000001B4898AF408>
<map object at 0x000001B489591C48>
<map object at 0x000001B48959D688>
<map object at 0x000001B4898CF608>
<map object at 0x000001B4898CF7C8>
<map object at 0x000001B489962908>

Now of course, rather than memory addresses (pointers to?), liked to see their content.现在当然不是 memory 地址(指针?),喜欢看他们的内容。 I've seen the loop itemizing the list solve this in another Q&A here?我在这里的另一个问答中看到了列出列表的循环解决了这个问题? Why isn't it working here?为什么它在这里不起作用? Thanks!谢谢!

Full answer is given by:完整答案由以下人员给出:

nodes = pd.read_table("Nodes10.csv", delimiter = " ")

nodes2 = nodes.to_dict("index")

new_list = [map(float, nodes2[i]['node,prob'].split(',')) for i in indices[0]]
          
l = len(new_list)
a = np.zeros(l)
i = 0
for item in new_list:
 
   for lm in item:
       a[i]=lm
   i = i+1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM