train = pd.read_csv('train_data_head_Chinese.csv', encoding="gb18030")
# 读取数据
# 其中有一列是“有无风险”
x = train['有无风险']
y = torch.tensor(x)
print(y)
# 以下为输出
tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
How to convert data in pandas into tensors?
Guess you like
Origin blog.csdn.net/huatianxue/article/details/114264723
Recommended
Ranking