1、Series唯一值判断
s = Series([3,3,1,2,4,3,4,6,5,6]) #判断Series中的值是否重复,False表示重复 print(s.is_unique) #False #输出Series中不重复的值,返回值没有排序,返回值的类型为数组 print(s.unique()) #[3 1 2 4 6 5] print(type(s.unique())) #<class 'numpy.ndarray'> #统计Series中重复值出现的次数,默认是按出现次数降序排序 print(s.value_counts()) ''' 3 3 6 2 4 2 5 1 2 1 1 1 ''' #按照重复值的大小排序输出频率 print(s.value_counts(sort=False)) ''' 1 1 2 1 3 3 4 2 5 1 6 2 '''
2、成员资格判断
a、Series的成员资格
s = Series([5,5,6,1,1]) print(s) ''' 0 5 1 5 2 6 3 1 4 1 ''' #判断矢量化集合的成员资格,返回一个bool类型的Series print(s.isin([5])) ''' 0 True 1 True 2 False 3 False 4 False ''' print(type(s.isin([5]))) #<class 'pandas.core.series.Series'> #通过成员资格方法选取Series中的数据子集 print(s[s.isin([5])]) ''' 0 5 1 5 '''
b、DataFrame的成员资格
a = [[3,2,6],[2,1,4],[6,2,5]] data = DataFrame(a,index=["a","b","c"],columns=["one","two","three"]) print(data) ''' one two three a 3 2 6 b 2 1 4 c 6 2 5 ''' #返回一个bool的DataFrame print(data.isin([1])) ''' one two three a False False False b False True False c False False False ''' #选取DataFrame中值为1的数,其他的为NaN print(data[data.isin([1])]) ''' one two three a NaN NaN NaN b NaN 1.0 NaN c NaN NaN NaN ''' #将NaN用0进行填充 print(data[data.isin([1])].fillna(0)) ''' one two three a 0.0 0.0 0.0 b 0.0 1.0 0.0 c 0.0 0.0 0.0 '''
以上这篇pandas的唯一值、值计数以及成员资格的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 冼佩瑾.2024-女儿Daughter(EP)【杰威尔】【FLAC分轨】
- 黑豹乐队.1993-光芒之神【摇音晨【WAV+CUE】
- 曾轶可.2011-一只猫的旅行【天娱传媒】【WAV+CUE】
- 黑神话悟空上品狼刺客精魄获取方法一览|上品狼刺客精魄收集攻略
- 视觉小说《神椿市建设中REGENERATE》将于2025年2月20日发售
- 黑神话悟空上品鼠弩手精魄获取方法一览|上品鼠弩手精魄收集攻略
- 中国音乐地图听见世界非物质文化遗产《非遗HQCD》wav
- 中国民乐合奏作品集《华夏之音HQ》头版限量编号[WAV+CUE]
- [电影原声带]黎允文《天将雄师》[FLAC+CUE]
- 曝NS继任机型已进入量产阶段:已花了30亿日元
- 不是Switch2?曝《马里奥惊奇》NS捆绑包即将公开
- 暖心任天堂!网友Switch维修返还时贴纸被完好保留
- 《国语老歌 经典对唱情歌 2CD》[WAV/分轨][1.1GB]
- 《刀郎 翻唱精选华语专辑 披着羊皮的狼 》[WAV+CUE][430MB]
- 《真的田震 中国乐坛红极一时的歌者 精品集》[WAV+CUE][300MB]