数据框DataFrame和列表List相互转换

DataFrame →List

 

 

import numpy as np
import pandas as pd
test = pd.DataFrame({ 'IDCARD' :['ID1','ID1','ID1','ID2','ID2'],
                     'TIME' :['2019/11/21','2019/11/29','2019/11/30','2019/1/28','2019/2/13']})
train_data = np.array(test) #先将数据框转换为数组
train_data_list = train_data.tolist()  #其次转换为列表
print(np.array(train_data_list))  #以数组形式打出来方便看

 

 输出结果:数据框DataFrame和列表List相互转换_第1张图片

 

 ListDataFrame

 

1 from pandas.core.frame import DataFrame
2 data_set = ['A','B','C']
3 data = DataFrame(data_set)  
4 #data = pd.DataFrame(data_set)
5 print(data)

输出结果:

你可能感兴趣的:(数据框DataFrame和列表List相互转换)