如何将numpy中的引号去掉

import pandas as pd
y_train = pd.read_csv(‘y_train.csv’)
y_train = y_train.values
print(y_train)
运行结果为:
[[‘[-5.946877]’]
[‘[-2.6266341]’]
[‘[1.4479955]’]

[‘[-0.8753087]’]
[‘[3.5259385]’]
[‘[4.88593]’]]
怎样能把里面的引号去掉

讨论数量: 1
Jason990420
import io
from ast import literal_eval
import pandas as pd

data = """
y_train
[-2.6266341]
[1.4479955]
[-0.8753087]
[3.5259385]
[4.88593]
""".strip()

dtype_data = {'y_train': list}
df = pd.read_csv(io.StringIO(data), converters={'y_train': literal_eval})
values = df.values
print(values)
[[list([-2.6266341])]
 [list([1.4479955])]
 [list([-0.8753087])]
 [list([3.5259385])]
 [list([4.88593])]]
>>> values[0][0]
[-2.6266341]
>>> type(values[0][0])
<class 'list'>
4周前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!