pandas的DataFrame

numpy

# 查看数组类型
np.dtype
# 二维数组建立
a_np=np.array([[1,3,5],[5,3,5],[44,35,55]])
# axis=0按列统计,axis=1按行统计

以numpy为基础的pandas(建立在数组之上).series

#创建series
import pandas as pd
a_series=pd.Series(['a','v','d'])
a_series.index.name='行索引'
# 设置index
b_series=pd.Series(['1','e','v'],index=['3','3','e'])
# 数据内容
a_series.values
# 行索引
a_series.index
# 行索引的名称
a_series.index.name
# series元素查找
# iloc绝对位置查找
a_series.iloc[0]
# loc索引查找
b_series.loc['第二个元素']
# series的元素个数
a_series.count()
# series的统计信息
a_series.describe()
# series的元素类型
a_series.dtype
# 两向量按照index相同进行相加,无法相加的显示NaN
c_series=a_series+b_series

DataFrame(由若干Series组成,共享一个index,列索引包含所有Series的列名称,列索引行索引均有name属性)

# df.values  数据内容
# df.index 行索引  df.index.name 行索引名字
# df.columns 列索引 df.columns.name  列索引名字
# 字典的key对应columns,
# 根据字典构造DataFrame
from collection import OrderedDict  # 引入有序字典
score_ord_dict=OrderedDict(score_dict) # 将字典转换为有序格式
score_df=DataFrame(score_ord_dict) # 将有序字典转换为DataFrame
# 统计功能,按列计算(每列数据的个数)
df.count()
# 描述性统计信息
df.describe()
# 查看数据类型
df.dtypes()
# 查看数据框大小
df.shape()
# iloc[行标,列标]
df.iloc[:,2]
# loc[行索引,列索引](包含尾列)
df.loc[['a','v'],['d','a']]
# 筛选行数据
df.loc[bool型数据,:]

pandas的DataFrame