【说站】Python中Series常用方法整理
2025-01-09
25
Python中Series常用方法整理
方法说明
1、排序sort_values和ascending。
通过ascending参数来确定升序还是降序,True表示升序
2、空判断,isnull和notnull。
isnull() - 判空
notnull() - 判非空
3、缺失值处理,dropna和删除。
dropna()
删除
4、统计基本信息describe()。
实例
>>> data a 10 b 11 c 12 d 13 e 14 dtype: int64 >>> data.sort_values(ascending = False) #降序排序 e 14 d 13 c 12 b 11 a 10 dtype: int64 >>> data = pd.Series([100,200,np.nan,200,np.nan,400],list('abcdef')) #创建含有缺失值的对象 >>> data a 100.0 b 200.0 c NaN d 200.0 e NaN f 400.0 dtype: float64 >>> data.isnull() #判空 a False b False c True d False e True f False dtype: bool >>> data.notnull() #判非空 a True b True c False d True e False f True dtype: bool >>> data.dropna() #删除缺失值 a 100.0 b 200.0 d 200.0 f 400.0 dtype: float64 >>> data.fillna(data.mean()) #设置默认值为均值 a 100.0 b 200.0 c 225.0 d 200.0 e 225.0 f 400.0 dtype: float64 >>> data.drop_duplicates() #去重 a 100.0 b 200.0 c NaN f 400.0 dtype: float64 >>> data.value_counts() #统计频率 200.0 2 100.0 1 400.0 1 dtype: int64 >>> data.describe() #对数据进行基本统计,统计时自动去掉了缺失值 count 4.000000 mean 225.000000 std 125.830574 min 100.000000 25% 175.000000 50% 200.000000 75% 250.000000 max 400.000000 dtype: float64
以上就是Python中Series常用方法整理,希望对大家有所帮助。更多Python学习指路:python基础教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
更新于:8天前赞一波!
相关文章
- 【说站】python数据结构堆的介绍
- 【说站】python参数调用的注意点
- 【说站】mysql有哪些建立索引的方法
- 【说站】mysql表导出的两种方法
- 【说站】python Pandas读取数据文件的优点
- 【说站】python中in和is的区分
- 【说站】python异常中常见关键字
- 【说站】python os.path.join()函数的使用
- 【说站】python如何使用skimage包提取图像
- 【说站】python confusion_matrix()是什么
- 【说站】python中os.path.join()函数是什么
- 【说站】python中有哪些比较操作
- 【说站】python字符串的用法总结
- 【说站】php方法断点如何实现
- 【说站】java类的两种引用方法
- 【说站】python列表数据如何增加和删除
- 【说站】python解释器的多种使用
- 【说站】python多行注释的方法整理
- Google翻译退出中国:带访问方法(已验证)
- 【说站】python列表有哪些特点
文章评论
评论问答