#0 导入模块
import numpy as np
import pandas as pd
#1 读取信息
import pandas as pd
df = pd.read_excel(‘数据_RFM实战.xlsx‘)
df
#2 限制显示行数
pd.set_option(‘max_rows‘, 10)
#3 显示前5行
df.head()
#4 显示后5行
df.tail()
<class ‘pandas.core.frame.DataFrame‘>
RangeIndex: 19 entries, 0 to 18
Data columns (total 4 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 买家昵称 19 non-null object
1 付款日期 19 non-null datetime64[ns]
2 订单状态 19 non-null object
3 实付金额 19 non-null int64
dtypes: datetime64[ns](1), int64(1), object(2)
memory usage: 736.0+ bytes
1 总体行数: 索引数:
2 总体列数:
3 每一列:多少行非空,数据类型
describe() 函数计算 Series 与 DataFrame 数据列的各种数据统计量。
描述性分析是所有数据分析新人、统计学新人在一开始了解的内容。因为常常用到,所有稍微介绍下 describe() ,做个总结。
DataFrame.describe(percentiles=None,
include=None,
exclude=None,
datetime_is_numeric=False)
?percentiles=None
:表示百分位数。介于0和1之间。默认值为 ,它返回第25、50和75个百分位数。[.25, .5, .75]
?include=None
:在描述DataFrame时包括数据类型列表。其默认值为无
?exclude=None
:在描述DataFrame时不包括数据类型列表。其默认值为无
?datetime_is_numeric=False
:bool,默认为False。是否将datetime dtypes视为数字。这会影响为该列计算的统计信息。
import pandas as pd
import numpy as np
data = {‘玩具‘:[‘轮船‘,‘飞机‘,‘轮船‘],
‘数量‘:[3,2,4],
‘价格‘:[100,90,80],
‘人员‘:[45,50,‘张三‘],
‘时间‘:[np.datetime64("2000-01-01"),np.datetime64("2010-01-01"),np.datetime64("2010-01-01")]
}
df = pd.DataFrame(data)
df
df.describe()
df.describe(include=[np.number]) #和默认一致
df.describe(include=[np.object]) #查看数值、唯一值等
df.describe(include=‘all‘)
df.describe(exclude=[np.object])
df.describe(datetime_is_numeric=True) #True的话同时也会将日期数据进行描述分析
count 3
mean 2006-09-01 08:00:00
min 2000-01-01 00:00:00
25% 2004-12-31 12:00:00
50% 2010-01-01 00:00:00
75% 2010-01-01 00:00:00
max 2010-01-01 00:00:00
dtype: object
原文:https://www.cnblogs.com/PythonSQL/p/14648226.html