Python:如何从字典中仅提取值?

标签 python dictionary pandas

我创建了一个字典d,其中A是包含数据的列表

class Driver(object):
    def __init__(self, name, raw_value, Id1):
        self.name = name
        self.raw = raw_value
        self.Indicator1 = Id1

d = {}
for i in range(0,len(A)):
    if not A[i].name in d:
        d[A[i].name] = [A[i].Indicator1]
    else:
        d[A[i].name] += [A[i].Indicator1]

所以

d[driver[0]] =

[0          0.002862
 1        -15.005252
 2          0.009653
 3        -15.192950
 4         14.941727
 5         44.977511
Name: 3, dtype: float64, 
 0          0.005229
 1         -0.230766
 2         14.803119
 3         -0.005263
 Name: 3, dtype: float64, 
 0         -3.756292
 1         14.827995
 2         45.595015
 3         44.964029
 4         14.820670
 Name: 3, dtype: float64]

如我的笔记本中的图片所示

enter image description here

我只想从中获取值,所以:

v = [0.002862, -15.005252, 0.009653,-15.192950, 14.941727, ..., 44.964029, 4.820670]

最佳答案

试试这个:

import pandas as pd

pd.concat(d[users[0]]).values

这会将您的 pandas 系列(或 numpy 数组)列表连接成一个列表,然后您可以应用 values 访问器来获取 numpy 数组或 .tolist() 函数以获取常规 Python 列表

关于Python:如何从字典中仅提取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37492705/

相关文章:

python - 如何提取值(value)

python - 从两个数据框中获取匹配字符串的索引

python - 使用 Geopandas 选择 .shp 文件的特定区域

python - 参数拆包浪费堆栈帧

python - 带有列表的字典 : Fastest way to get the key corresponding to the minimum value of the fourth list item?

python - 将值 append 到 Python 字典

python - 对列中的所有行对执行操作

python - images.get_serving_url() 可以服务哪些类型的文件?

python - 谷歌云机器学习 : Outer dimension for outputs must be unknown

python - 追加嵌套字典