首先使用np.array()函数把DataFrame转化为np.ndarray(),再利用tolist()函数把np.ndarray()转为list,示例代码如下:
1
2
3
4
5
6
7
8
9
10
11
|
# -*- coding:utf-8-*-
import numpy as np
import pandas as pd
data_x = pd.read_csv("E:/Tianchi/result/features.csv",usecols=[2,3,4])#pd.dataframe
data_y = pd.read_csv("E:/Tianchi/result/features.csv",usecols=[5])
train_data = np.array(data_x)#np.ndarray()
train_x_list=train_data.tolist()#list
print(train_x_list)
print(type(train_x_list))
|
以上这篇pandas DataFrame数据转为list的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/xiangxianghehe/article/details/72615711