pandas 数据填充
可以使用前面 后面 上面 下面值填充
df = pd.DataFrame({
"animal": ["", "安全能力", "1", ],
"color": ["", "安全能力", "5.1.1"],
"name": ['安全能力等级', "一级", "√"],
"name1": ["", "二级", "√"],
"name2": ["", "三级级", "√"],
"name3": ["", "四级", "√"],
"age": ["", "五级", "√"],
})
df2 = df.replace('', None)
df2 = df2.fillna(method='pad', axis=0)
df2 = df2.fillna(method='pad', axis=1)
df2 = df2.fillna(method='backfill', axis=1)
df2 = df2.fillna(method='backfill', axis=0)
print(df2)
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/17773010.html