相干扩大库
1# -*- coding: UTF-8 -*-23import pandas as pd45data_dict = {'first_col': [1, 2, 3, 4], 'second_col': [5, 6, 7, 8]}67df = pd.DataFrame(data_dict)
统计简略信息
1# 生成简要的数据统计数据 2 3describe(percentiles=None, include=None, exclude=None) 4# first_col second_col 5# count 4.000000 4.000000 总数量 6# mean 2.500000 6.500000 均值 7# std 1.290994 1.290994 方差 8# min 1.000000 5.000000 最小值 9# 25% 1.750000 5.750000 25%数据量时的数据10# 50% 2.500000 6.500000 50%数据量时的数据11# 75% 3.250000 7.250000 75%数据量时的数据12# max 4.000000 8.000000 最大值1314# percentiles 指定统计量,默认是25%、50%、75%时的数据量15# include 蕴含数据类型,include='all'同时蕴含离散型与数值型的统计特色、include='O'蕴含离散型、默认include=None蕴含数值型16# exclude 不蕴含数据类型,exclude='O'不蕴含离散型1718print(df.describe(percentiles=[.2,.4,.6,.8], include=None, exclude='O'))
head()与tail()函数
1# head() 函数前多少行23print(df.head(2))45# tail() 函数后多少行67print(df.tail(2))数据聚合统计 1# 获取某一列的和 2 3print(df['first_col'].sum()) 4 5# 获取某一列的均值 6 7print(df['first_col'].mean()) 8 9# 获取某一列的总数量1011print(df['first_col'].count())1213# 获取某一列的最大值1415print(df['first_col'].max())1617# 获取某一列的最小值1819print(df['first_col'].min())
数据结构统计
1# 返回列的数据类型 2 3print(df.dtypes) 4 5# size()返回数据总数 6 7print(df.size) 8 9# 返回数据形态,几行几列1011print(df.shape)1213# 返回列数1415print(df.ndim)1617# 返回每一列的名称1819print(df.axes)
更多精彩返回微信公众号【Python 集中营】,专一于 python 技术栈,材料获取、交换社区、干货分享,期待你的退出~