pandas DataFrame学习(1)

pandas DataFrame学习

关于pandas,前人之述备矣。然则this is my Blog!

创建一个dataframe

dataframe是个数据表。可以通过字典创建(有一维、两维)

import pandas as pd
####嵌套字典创建df
dic3 = {'one':{'a':1,'b':2,'c':3,'d':4}, 
'two':{'a':5,'b':6,'c':7,'d':8},
'three':{'a':9,'b':10,'c':11,'d':12}}
df3 = pd.DataFrame(dic3)
print ('下标:'+df3.index) #查看下标
print'type:%s'%type(df3)) #数据类型

输出结果:
pic1

分别声明名称和索引:

使用.Series和.index方法分别声明。

s4 = pd.Series(np.array([1,1,2,3,5,8]))
s4.index = ['a','b','c','d','e','f']
print (s4['e'],s4[3])

输出结果:
pic2

自动对齐功能

s5 = pd.Series(np.array([10,15,20,30,55,80]),
index = ['a','b','c','d','e','f'])
s6 = pd.Series(np.array([12,11,13,15,14,16]),
index = ['a','c','g','b','d','f'])
s5 + s6
s5/s6

输出结果:
pic3

Tips

发现jupyter在上一个in里面如果声明的东西,在下一个In中也可以使用。它整体的一个文件就是拆分成很多块的程序。(终于明白jupyter的真正优点了)

posted @ 2018-01-18 17:23  Jneeee  阅读(224)  评论(0编辑  收藏  举报