本文基于python3
import pandas as pd
labels=["year","month","day","hour","minutes"]
dataset=[[2018,12,21,6,32],
[2018,12,21,6,32],
[2018,12,21,6,32],
[2018,12,21,6,32],
[2018,12,21,6,32],
]
second2=[50,50,50,50,50]
second1=[[51],[51],[51],[51],[51],]
test1=pd.DataFrame(dataset,columns=labels)
test2=pd.DataFrame(dataset,columns=labels)
test1["second1"]=second1
test2["second2"]=second2
print(test1)
print(test2)输出如下:
year month day hour minutes second1
0 2018 12 21 6 32 [51]
1 2018 12 21 6 32 [51]
2 2018 12 21 6 32 [51]
3 2018 12 21 6 32 [51]
4 2018 12 21 6 32 [51]
year month day hour minutes second2
0 2018 12 21 6 32 50
1 2018 12 21 6 32 50
2 2018 12 21 6 32 50
3 2018 12 21 6 32 50
4 2018 12 21 6 32 50
在python中,普通的列表list和numpy中的数组array是不一样的,最大的不同是:一个列表中可以存放不同类型的数据,包括int、float和str,甚至布尔型;而一个数组中存放的数据类型必须全部相同,int或float。
在list中的数据类型保存的是数据的存放的地址,简单的说就是指针,并非数据,这样保存一个list就太麻烦了,例如list1=[1,2,3,4]需要4个指针和四个数据,增加了存储和消耗cpu,而array1=numpy.array([1,2,3,4])只需要存放四个数据,读取和计算更