【coding】pandas返回文本序列长度及其描述性统计
文本长度统计
pandas时不要盲目的使用for-loop,费时费力;要熟练掌握pandas提供的内置函数。
df_len_a = df['a'].str.len()
#返回的df_len_a本身也是个pandas.core.series.Series数值化序列数据
快速筛选出长度大于某个值的所有行
df[df['a'].str.len() > 100]
数值序列描述性统计
df_len_a.count() #非空观测数量
df_len_a.sum() #所有值之和
df_len_a.mean() #所有值的平均值
df_len_a.median() #所有值的中位数
df_len_a.mode() #值的模值
df_len_a.std() #值的标准偏差
df_len_a.min() #所有值中的最小值
df_len_a.max() #所有值中的最大值
df_len_a.abs() #绝对值
df_len_a.prod() #数组元素的乘积
df_len_a.cumsum() #累计总和
df_len_a.cumprod() #累计乘积