Pandas中 常用属性,查看概览信息

DataFrame的基础属性

df.shape ——行数 列数
df.dtypes——列数据类型
df.ndim ——数据维度
df.index——行索引
df.columns——列索引
df.values——对象值,二维ndarray数组


DataFrame整体情况

df.head(10)——显示前10行,默认是5行
df.tail()——显示末尾几行,默认是5
df.info()——相关系数,如行数,列数,列索引、列非空值个数,列类型,内存占用
df.describe()——快速统计结果,计数、均值、标准差、最大值、四分数、最小值


Example
>>> import numpy as np
>>> import pandas as pd
>>> df1 = pd.DataFrame(np.arange(12, 24).reshape((3,4)), columns=["W","X","Y","Z"])
>>> print(df1)
    W   X   Y   Z
0  12  13  14  15
1  16  17  18  19
2  20  21  22  23
>>> print(df1.index)
RangeIndex(start=0, stop=3, step=1)
>>> print(df1.columns)
Index(['W', 'X', 'Y', 'Z'], dtype='object')
>>> print(df1.values)
[[12 13 14 15]
 [16 17 18 19]
 [20 21 22 23]]
>>> print(df1.shape)
(3, 4)
>>> print(df1.ndim)
2
>>> print(df1.dtypes)
W    int32
X    int32
Y    int32
Z    int32
dtype: object
>>> print(df1.head(2))
    W   X   Y   Z
0  12  13  14  15
1  16  17  18  19
>>> print(df1.tail(3))
    W   X   Y   Z
0  12  13  14  15
1  16  17  18  19
2  20  21  22  23


>>> print(df1.info())
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 4 columns):
W    3 non-null int32
X    3 non-null int32
Y    3 non-null int32
Z    3 non-null int32
dtypes: int32(4)
memory usage: 128.0 bytes
None



>>> print(df1.describe()) #(只统计列)
          W     X     Y     Z
count   3.0   3.0   3.0   3.0
mean   16.0  17.0  18.0  19.0
std     4.0   4.0   4.0   4.0
min    12.0  13.0  14.0  15.0
25%    14.0  15.0  16.0  17.0
50%    16.0  17.0  18.0  19.0
75%    18.0  19.0  20.0  21.0
max    20.0  21.0  22.0  23.0
  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凯旋的皇阿玛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值