pandas对指定列进行填充的方法
作者:GeekLeee 时间:2022-03-15 07:52:51
实例如下所示:
>>> import pandas as pd
>>> import numpy as np
>>> ts1 = [0, 1, np.nan, np.nan, np.nan, np.nan]
>>> ts2 = [0, 2, np.nan, 3, np.nan, np.nan]
>>> d = {'X': ts1, 'Y': ts2, 'Z': ts2}
>>> df = pd.DataFrame(data=d)
>>> df
X Y Z
0 0.0 0.0 0.0
1 1.0 2.0 2.0
2 NaN NaN NaN
3 NaN 3.0 3.0
4 NaN NaN NaN
5 NaN NaN NaN
>>> col =['X','Y']
>>> df[col] = df[col].ffill()
>>> df
X Y Z
0 0.0 0.0 0.0
1 1.0 2.0 2.0
2 1.0 2.0 NaN
3 1.0 3.0 3.0
4 1.0 3.0 NaN
5 1.0 3.0 NaN
>>>
来源:https://blog.csdn.net/GeekLeee/article/details/75271233
标签:pandas,填充,列
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Oracle性能究极优化 下
2010-07-30 13:25:00
python中threading开启关闭线程操作
2022-10-02 22:40:26
基于python实现MQTT发布订阅过程原理解析
2023-05-06 14:45:14
![](https://img.aspxhome.com/file/2023/5/135055_0s.png)
Python中利用ItsDangerous快捷实现数据加密
2022-06-09 23:24:41
![](https://img.aspxhome.com/file/2023/3/67283_0s.jpg)
详解使用PyInstaller将Pygame库编写的小游戏程序打包为exe文件
2023-11-10 13:20:31
![](https://img.aspxhome.com/file/2023/2/109992_0s.png)
ASP中 ADODB.Stream 语法速查
2008-01-27 15:23:00
详解new function(){}和function(){}()
2008-02-28 12:28:00
Python NumPy教程之数据类型对象详解
2022-03-29 09:05:19
javascript 45种缓动效果(一)
2009-09-19 18:30:00
使用keras实现孪生网络中的权值共享教程
2022-10-21 13:52:34
![](https://img.aspxhome.com/file/2023/3/124403_0s.jpg)
Go单元测试对GORM进行Mock测试
2023-07-20 17:38:53
在VSCode中配置PHP开发环境的实战步骤
2023-06-06 02:13:06
![](https://img.aspxhome.com/file/2023/9/55349_0s.png)
Python基础知识学习之类的继承
2022-09-02 15:41:05
用Python实现写倒序输出(任意位数)
2023-06-12 17:46:33
写给应聘页面重构的同学
2009-03-18 11:01:00
Python函数中apply、map、applymap的区别
2022-08-11 04:20:36
Python3自动签到 定时任务 判断节假日的实例
2022-11-15 15:48:48
写给JavaScript库开发者们的规则
2008-10-26 12:30:00
python3.6环境下安装freetype库和基本使用方法(推荐)
2023-04-21 19:43:00
![](https://img.aspxhome.com/file/2023/0/135050_0s.jpg)
python利用datetime模块计算时间差
2021-10-07 01:02:04