Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从数据帧内的列中解析出数组?_Python_Pandas - Fatal编程技术网

Python 如何从数据帧内的列中解析出数组?

Python 如何从数据帧内的列中解析出数组?,python,pandas,Python,Pandas,我有一个如下所示的数据框: Index Values Digits 1 [1.0,0.13,0.52...] 3 2 [1.0,0.13,0.32...] 3 3 [1.0,0.31,0.12...] 1 4 [1.0,0.30,0.20...] 2 5 [1.0,0.30,0.20...] 3 我的输出应该是: Index Value

我有一个如下所示的数据框:

Index   Values                Digits 
1       [1.0,0.13,0.52...]       3
2       [1.0,0.13,0.32...]       3
3       [1.0,0.31,0.12...]       1
4       [1.0,0.30,0.20...]       2
5       [1.0,0.30,0.20...]       3
我的输出应该是:

Index   Values                Digits 
1       [0.33,0.04,0.17...]       3
2       [0.33,0.04,0.11...]       3
3       [0.33,0.10,0.40...]       1
4       [0.33,0.10,0.07...]       2
5       [0.33,0.10,0.07...]       3
我相信Values列在单元格中有一个np.array?从技术上讲,这是一个数组

我希望解析出Values列,并将数组中的所有值除以3

我的尝试已在解析以下值时停止:

a = df(df['Values'].values.tolist())

IIUC,
应用列表计算

df.Values.apply(lambda x : [y/3 for y in x])
Out[1095]: 
0    [0.3333333333333333, 0.043333333333333335, 0.1...
1    [0.3333333333333333, 0.043333333333333335, 0.1...
Name: Values, dtype: object
#df.Values=df.Values.apply(lambda x : [y/3 for y in x])

IIUC,
应用列表计算

df.Values.apply(lambda x : [y/3 for y in x])
Out[1095]: 
0    [0.3333333333333333, 0.043333333333333335, 0.1...
1    [0.3333333333333333, 0.043333333333333335, 0.1...
Name: Values, dtype: object
#df.Values=df.Values.apply(lambda x : [y/3 for y in x])

创建的数据帧:

import pandas as pd
d = {'col1': [[1,10], [2,20]], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
def divide_by_3(lst):
    outpuut =[]
    for i in lst:
        outpuut.append(i/3.0)
    return outpuut
创建的函数:

import pandas as pd
d = {'col1': [[1,10], [2,20]], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
def divide_by_3(lst):
    outpuut =[]
    for i in lst:
        outpuut.append(i/3.0)
    return outpuut
应用功能:

df.col1.apply(divide_by_3`)
0    [0.333333333333, 3.33333333333]
1    [0.666666666667, 6.66666666667]
结果:

df.col1.apply(divide_by_3`)
0    [0.333333333333, 3.33333333333]
1    [0.666666666667, 6.66666666667]

创建的数据帧:

import pandas as pd
d = {'col1': [[1,10], [2,20]], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
def divide_by_3(lst):
    outpuut =[]
    for i in lst:
        outpuut.append(i/3.0)
    return outpuut
创建的函数:

import pandas as pd
d = {'col1': [[1,10], [2,20]], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
def divide_by_3(lst):
    outpuut =[]
    for i in lst:
        outpuut.append(i/3.0)
    return outpuut
应用功能:

df.col1.apply(divide_by_3`)
0    [0.333333333333, 3.33333333333]
1    [0.666666666667, 6.66666666667]
结果:

df.col1.apply(divide_by_3`)
0    [0.333333333333, 3.33333333333]
1    [0.666666666667, 6.66666666667]