pandas 学习汇总9 - Series系列,DataFrame数据帧 属性( tcy)
发布日期:2021-06-29 14:48:04 浏览次数:2 分类:技术文章

本文共 2361 字,大约阅读时间需要 7 分钟。

Series-属性  2018/11/8  2018/12/6

序列: 

# 可以把Series看成有序字典;均匀数据;尺寸数据均可变s=pd.Series(data=np.arange(10,15),index=pd.Index(list('abcde')),dtype=np.float, name='Series-1')

属性简表:

属性 说明
s.at[] 访问行/列标签对的单个值。
s.axes 返回行轴标签列表 [Index(['a', 'b', 'c', 'd', 'e'], dtype='object')]
s.dtype 返回基础数据的dtype对象dtype('float64')
s.dtypes 返回基础数据的dtype对象dtype('float64')
s.empty 系列为空返回 True
s.flags  -
s.ftype 如数据稀疏则返回 'float64:dense'
s.ftypes 如数据稀疏则返回 'float64:dense'
s.hasnans 如有nans返回True False
s.iat[] 按整数位置访问行/列对的单个值。
s.iloc[] 纯粹基于整数位置的索引,用于按位置选择。
s.imag array([0., 0., 0., 0., 0.])
s.imag array([0., 0., 0., 0., 0.])
s.index 系列索引(轴标签)Index(['a', 'b', 'c', 'd', 'e'], dtype='object')
s.is_monotonic 如序列中值递增返回True
s.is_monotonic_decreasing 如序列中值递减返回True
s.is_monotonic_increasing 如序列中值递增返回True
s.is_unique 如果对象中的所有值都是唯一返回True
s.itemsize 返回基础数据项的dtype的大小 8
s.ix[] 主要基于标签位置的索引器,具有整数位置回退。
s.loc[] 通过标签或布尔数组访问一组行和列。
s.memory_usage() 返回Series的内存使用情况240
s.nbytes 返回基础数据字节数 40
s.ndim 返回基础数据维数 1
s.real array([10., 11., 12., 13., 14.])
s.shape 返回数据形状元组 (5,)
s.size 返回数据元素数量 5
s.strides 返回数据步幅 (8,)
s.values 返回系列值 dtype array([10., 11., 12., 13., 14.])

实例: 

s.flags'''C_CONTIGUOUS : TrueF_CONTIGUOUS : TrueOWNDATA : TrueWRITEABLE : TrueALIGNED : TrueWRITEBACKIFCOPY : FalseUPDATEIFCOPY : False''' 

 DataFrame-属性   2018/12/7  

属性: 

# 所有Pandas数据结构是值可变的(数值大小可更改)# DataFrame索引(行)和列(不同类型) ;大小可变 可对行和列执行算术运算data = {'Name':pd.Series(['Tom','Jim','Bob']),'Age':pd.Series([25,26,25]),'sex':pd.Series([0,1,0],dtype=bool)}df=pd.DataFrame(data)  

简表:

属性 说明
df.at[] 访问行/列标签对的单个值
df.axes 行轴标签列表 [RangeIndex(start=0, stop=3, step=1),
 - Index(['Name', 'Age', 'sex'], dtype='object')]
df.columns 列标签#Index(['Name', 'Age', 'sex'], dtype='object')
df.dtypes 数据类型 #Name object Age int64 sex bool dtype: object
df.empty 对象为空返回True 
df.ftypes 返回数据帧中的ftypes(稀疏/密集和dtype的指示)
df.iat[] 按整数位置访问行/列对的单个值
df.iloc[] 整数位置索引,用于按位置选择
df.index 索引行标签  #RangeIndex(start=0, stop=3, step=1)
df.ix[] 主要基于标签位置的索引器,具有整数位置回退
df.loc[] 通过标签或布尔数组访问一组行和列
df.memory_usage() 内存使用情况#Index 80 Name 24 Age 24 sex 3 dtype: int64
df.ndim 基础数据维数 2
df.shape 数据形状元组 (3, 3)
df.size 数据元素数量 9
df.style 返回Styler对象的属性# pandas.io.formats.style.Styler
df.T 转置
df.values 返回数据帧的ndarray #array([['Tom', ...],…,  dtype=object)

 

实例:

df.T# 0 1 2# Name Tom Jim Bob# Age 25 26 25# sex False True Falsedf.ftypes# Name object:dense# Age int64:dense# sex bool:dense# dtype: object  

 

 

 

转载地址:https://chunyou.blog.csdn.net/article/details/84780143 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:pandas 学习汇总10 - 统计:窗口函数rolling,expanding( tcy)
下一篇:matplotlib键盘鼠标事件(tcy)

发表评论

最新留言

不错!
[***.144.177.141]2024年04月11日 09时56分26秒