pandas处理缺失值的函数_pandas填充缺失值
pandas 处理 函数 填充 缺失
2023-06-13 09:13:38 时间
大家好,又见面了,我是你们的朋友全栈君。
df.dropna()函数用于删除dataframe数据中的缺失数据,即 删除NaN数据.
官方函数说明:
DataFrame.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
Remove missing values.
See the User Guide for more on which values are considered missing,
and how to work with missing data.
Returns
DataFrame
DataFrame with NA entries dropped from it.
参数说明:
Parameters | 说明 |
---|---|
axis | 0为行 1为列,default 0,数据删除维度 |
how | {‘any’, ‘all’}, default ‘any’,any:删除带有nan的行;all:删除全为nan的行 |
thresh | int,保留至少 int 个非nan行 |
subset | list,在特定列缺失值处理 |
inplace | bool,是否修改源文件 |
测试:
>>>df = pd.DataFrame({
"name": ['Alfred', 'Batman', 'Catwoman'],
"toy": [np.nan, 'Batmobile', 'Bullwhip'],
"born": [pd.NaT, pd.Timestamp("1940-04-25"),
pd.NaT]})
>>>df
name toy born
0 Alfred NaN NaT
1 Batman Batmobile 1940-04-25
2 Catwoman Bullwhip NaT
删除至少缺少一个元素的行:
>>>df.dropna()
name toy born
1 Batman Batmobile 1940-04-25
删除至少缺少一个元素的列:
>>>df.dropna(axis=1)
name
0 Alfred
1 Batman
2 Catwoman
删除所有元素丢失的行:
>>>df.dropna(how='all')
name toy born
0 Alfred NaN NaT
1 Batman Batmobile 1940-04-25
2 Catwoman Bullwhip NaT
只保留至少2个非NA值的行:
>>>df.dropna(thresh=2)
name toy born
1 Batman Batmobile 1940-04-25
2 Catwoman Bullwhip NaT
从特定列中查找缺少的值:
>>>df.dropna(subset=['name', 'born'])
name toy born
1 Batman Batmobile 1940-04-25
修改原数据:
>>>df.dropna(inplace=True)
>>>df
name toy born
1 Batman Batmobile 1940-04-25
以上。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/192382.html原文链接:https://javaforall.cn
相关文章
- panda’_pandas map
- Numpy&Pandas快速上手篇
- Python数据分析之Pandas(五)
- Pandas 创建DataFrame提示:type object ‘object‘ has no attribute ‘dtype‘
- 用python的pandas打开csv文件_如何使用Pandas DataFrame打开CSV文件 – python[通俗易懂]
- Python处理Excel数据-pandas篇
- pandas删除某列有空值的行_drop的之
- pandas_VS_Excel统计各班成绩的最大最小平均分合格优秀尖子人数
- 深入浅出vue_深入浅出pandas
- Excel与pandas:使用applymap()创建复杂的计算列
- pandas group by + rank 求在分组内的百分位、最接近某百分位的行
- Pandas处理大数据的性能优化技巧
- python内置库和pandas中的时间常见处理(3)
- pandas(一)操作Series和DataFrame的基本功能详解大数据
- andas探索MySQL与Pandas的结合之美(mysqlp)
- 利用Pandas与MSSQL进行数据分析(pandas mssql)