如何在Python中将1添加到数字列中并将空值替换为1

问题描述 投票:0回答:1
out_df['# of Days'] = out_df['# of Days'].replace('',1)
out_df['# of Days'] += 1

print(out_df)

除非单元格的值为 NULL,否则它不会添加 1 值。

尝试将 1 添加到整个列,包括列中的空单元格。

addition
1个回答
0
投票
def newValue(value):
    if value == "":
        return 1
    if value is None:
        return 1
    return value + 1

out_df['# of Days'] = newValue(out_df['# of Days'])
© www.soinside.com 2019 - 2024. All rights reserved.