dangdangA

导航

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

DataFrame →List

 

 

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

 

 

 输出结果:

 

 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)

 

输出结果:

posted on 2019-12-25 19:04  dangdangA  阅读(46196)  评论(0编辑  收藏  举报