Python pandas,DataFrame常用属性,查看DataFrame的概览和统计信息

 

Python pandas,DataFrame常用属性,查看DataFrame的概览和统计信息_第1张图片

 

demo.py:

# coding=utf-8
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(type(df1.values))  # 
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    int64
X    int64
Y    int64
Z    int64
dtype: object
'''

print(df1.head(2))  # 显示前几行。默认前5行
'''
    W   X   Y   Z
0  12  13  14  15
1  16  17  18  19
'''

print(df1.tail(2))  # 显示末尾几行。默认末尾5行
'''
    W   X   Y   Z
1  16  17  18  19
2  20  21  22  23
'''

# 展示DataFrame的概览
print(df1.info())
'''

RangeIndex: 3 entries, 0 to 2
Data columns (total 4 columns):
W    3 non-null int64
X    3 non-null int64
Y    3 non-null int64
Z    3 non-null int64
dtypes: int64(4)
memory usage: 176.0 bytes
None
'''

# 显示DataFrame的统计信息 (只能统计数值类型的列)
print(df1.describe())  # mean均值 std标准差  50%中位数  25%四分位数
'''
          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
'''

 

 

你可能感兴趣的:(Python+)