#dtype of lists is object
#https://stackoverflow.com/a/42672574/2901002
print (df['col1'].dtype)
object
#first value of column col1
print (df.loc[0, 'col1'])
['-0.8783137', '0.05478287', '-0.08827557', '0.69203985', '0.06209986']
#type of first value of column col1 is list
print (type(df.loc[0, 'col1']))
<class 'list'>
#first value of column col1 and first value of list
print (df.loc[0, 'col1'][0])
-0.8783137
#first value of column col1 and type of first value of list
print (type(df.loc[0, 'col1'][0]))
<class 'str'>
df['col1'] = df['col1'].apply(lambda x: [float(y) for y in x])
#another solution
df['col1'] = [[float(y) for y in x] for x in df['col1']]
print (df)
col1
0 [-0.8783137, 0.05478287, -0.08827557, 0.692039...
1 [0.31444644, -0.6546649, 0.7211526, 0.9819127,...
#dtype of lists is object
#https://stackoverflow.com/a/42672574/2901002
print (df['col1'].dtype)
object
#first value of column col1
print (df.loc[0, 'col1'])
[-0.8783137, 0.05478287, -0.08827557, 0.69203985, 0.06209986]
#type of first value of column col1 is list
print (type(df.loc[0, 'col1']))
<class 'list'>
#first value of column col1 and first value of list
print (df.loc[0, 'col1'][0])
-0.8783137
#first value of column col1 and type of first value of list
print (type(df.loc[0, 'col1'][0]))
<class 'float'>
3条答案
按热度按时间xmd2e60i1#
锁定21小时,该答案已被禁止评论,但仍接受其他互动Learn more。
EDIT 1:如果需要将字符串列表转换为浮点数列表:
EDIT 2:如果需要列表中的DataFrame-每个列表具有相同的长度:
2guxujil2#
你可以试试
v1uwarro3#
检查第一个值
这是一个浮点值列表。