导入:
import pandas as pd
import numpy as np
from numpy import nan as NaN
填充同样的内容:
df1.fillna(100)
每一列填充不一样的内容:
dict = {0:10,1:20,2:30}
df1.fillna(dict)
# 0列,1列,2列
直接修改原数据:
df1.fillna(0,inplace=True)
df1
修改填充方向:
df2.fillna(method="ffill",limit=1,axis=1)
ref:https://blog.csdn.net/haoxun05/article/details/104563911
DataFrame.fillna(value=None, method=None, axis=None, inplace=False, limit=None, downcast=None, **kwargs)
parameters | details |
---|---|
value | 被填充的数据,scalar、dict、Series、DataFrame |
method | backfill、bfill、pad、ffill |
axis | 0-index,1-columns修改填充方向 |
inplace | default False,if True means 修改原文件 |
limit | 限制填充个数 |
ref:https://blog.csdn.net/The_Time_Runner/article/details/84102428